diff options
author | Gabriel Caruso <carusogabriel34@gmail.com> | 2020-09-14 16:06:18 +0200 |
---|---|---|
committer | Gabriel Caruso <carusogabriel34@gmail.com> | 2020-09-15 12:56:10 +0200 |
commit | 1a8936cde3a14a1fdcd0f2a4cd567e5a3e206e65 (patch) | |
tree | 5afaedeff999ce14856d493d56245ab72dd0957a /ext/reflection/php_reflection.c | |
parent | c1823c6c8a1770734ab356090405849d2e9fec07 (diff) | |
download | php-git-1a8936cde3a14a1fdcd0f2a4cd567e5a3e206e65.tar.gz |
Check `ReflectionReference::fromArrayElement` with union types
ReflectionReference::fromArrayElement(array $array, int|string $key): ?ReflectionReference
is going to be its official signature for PHP 8.0.
Closes GH-5651
Diffstat (limited to 'ext/reflection/php_reflection.c')
-rw-r--r-- | ext/reflection/php_reflection.c | 20 |
1 files changed, 10 insertions, 10 deletions
diff --git a/ext/reflection/php_reflection.c b/ext/reflection/php_reflection.c index 403c91c3e4..292e1901e4 100644 --- a/ext/reflection/php_reflection.c +++ b/ext/reflection/php_reflection.c @@ -6084,20 +6084,20 @@ static zend_bool is_ignorable_reference(HashTable *ht, zval *ref) { ZEND_METHOD(ReflectionReference, fromArrayElement) { HashTable *ht; - zval *key, *item; + zval *item; + zend_string *string_key = NULL; + zend_long int_key = 0; reflection_object *intern; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "hz", &ht, &key) == FAILURE) { - RETURN_THROWS(); - } + ZEND_PARSE_PARAMETERS_START(2, 2) + Z_PARAM_ARRAY_HT(ht) + Z_PARAM_STR_OR_LONG(string_key, int_key) + ZEND_PARSE_PARAMETERS_END(); - if (Z_TYPE_P(key) == IS_LONG) { - item = zend_hash_index_find(ht, Z_LVAL_P(key)); - } else if (Z_TYPE_P(key) == IS_STRING) { - item = zend_symtable_find(ht, Z_STR_P(key)); + if (string_key) { + item = zend_hash_find(ht, string_key); } else { - zend_argument_type_error(2, "must be of type string|int, %s given", zend_zval_type_name(key)); - RETURN_THROWS(); + item = zend_hash_index_find(ht, int_key); } if (!item) { |