Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 8.1k
Promote the warning of array_key_exists() to exception#4887
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| --TEST-- | ||
| Using isset() with arrays | ||
| --FILE-- | ||
| <?php | ||
| $array = [ | ||
| 0 => true, | ||
| "a" => true, | ||
| ]; | ||
| var_dump(isset($array[0])); | ||
| var_dump(isset($array["a"])); | ||
| var_dump(isset($array[false])); | ||
| var_dump(isset($array[0.6])); | ||
| var_dump(isset($array[true])); | ||
| var_dump(isset($array[null])); | ||
| var_dump(isset($array[STDIN])); | ||
| try { | ||
| isset($array[[]]); | ||
| } catch (TypeError $exception) { | ||
| echo $exception->getMessage() . "\n"; | ||
| } | ||
| try { | ||
| isset($array[new stdClass()]); | ||
| } catch (TypeError $exception) { | ||
| echo $exception->getMessage() . "\n"; | ||
| } | ||
| ?> | ||
| --EXPECTF-- | ||
| bool(true) | ||
| bool(true) | ||
| bool(true) | ||
| bool(true) | ||
| bool(false) | ||
| bool(false) | ||
| Warning: Resource ID#%d used as offset, casting to integer (%d) in %s on line %d | ||
| bool(false) | ||
| Illegal offset type in isset or empty | ||
| Illegal offset type in isset or empty | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1531,7 +1531,7 @@ ZEND_API int array_set_zval_key(HashTable *ht, zval *key, zval *value) /* {{{ */ | ||
| result = zend_symtable_update(ht, ZSTR_EMPTY_ALLOC(), value); | ||
| break; | ||
| case IS_RESOURCE: | ||
| zend_error(E_NOTICE, "Resource ID#%d used as offset, casting to integer (%d)", Z_RES_HANDLE_P(key), Z_RES_HANDLE_P(key)); | ||
| zend_error(E_WARNING, "Resource ID#%d used as offset, casting to integer (%d)", Z_RES_HANDLE_P(key), Z_RES_HANDLE_P(key)); | ||
kocsismate marked this conversation as resolved.
Outdated
Uh oh!There was an error while loading. Please reload this page. | ||
| result = zend_hash_index_update(ht, Z_RES_HANDLE_P(key), value); | ||
| break; | ||
| case IS_FALSE: | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -436,7 +436,7 @@ static int zend_ast_add_array_element(zval *result, zval *offset, zval *expr) | ||
| zend_hash_index_update(Z_ARRVAL_P(result), zend_dval_to_lval(Z_DVAL_P(offset)), expr); | ||
| break; | ||
| case IS_RESOURCE: | ||
| zend_error(E_NOTICE, "Resource ID#%d used as offset, casting to integer (%d)", Z_RES_HANDLE_P(offset), Z_RES_HANDLE_P(offset)); | ||
| zend_error(E_WARNING, "Resource ID#%d used as offset, casting to integer (%d)", Z_RES_HANDLE_P(offset), Z_RES_HANDLE_P(offset)); | ||
| zend_hash_index_update(Z_ARRVAL_P(result), Z_RES_HANDLE_P(offset), expr); | ||
| break; | ||
| default: | ||
kocsismate marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| @@ -451,7 +451,7 @@ static int zend_ast_add_unpacked_element(zval *result, zval *expr) { | ||
| HashTable *ht = Z_ARRVAL_P(expr); | ||
| zval *val; | ||
| zend_string *key; | ||
| ZEND_HASH_FOREACH_STR_KEY_VAL(ht, key, val) { | ||
| if (key) { | ||
| zend_throw_error(NULL, "Cannot unpack array with string keys"); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -400,7 +400,7 @@ static int ZEND_FASTCALL zend_jit_fetch_dim_isset_helper(zend_array *ht, zval *d | ||
| hval = zend_dval_to_lval(Z_DVAL_P(dim)); | ||
| goto num_index; | ||
| case IS_RESOURCE: | ||
| //zend_error(E_WARNING, "Resource ID#%d used as offset, casting to integer (%d)", Z_RES_HANDLE_P(dim), Z_RES_HANDLE_P(dim)); | ||
| zend_error(E_WARNING, "Resource ID#%d used as offset, casting to integer (%d)", Z_RES_HANDLE_P(dim), Z_RES_HANDLE_P(dim)); | ||
kocsismate marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| hval = Z_RES_HANDLE_P(dim); | ||
| goto num_index; | ||
| case IS_FALSE: | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -40,6 +40,7 @@ | ||
| #include "php_math.h" | ||
| #include "zend_smart_str.h" | ||
| #include "zend_bitset.h" | ||
| #include "zend_exceptions.h" | ||
| #include "ext/spl/spl_array.h" | ||
| /* {{{ defines */ | ||
| @@ -765,6 +766,7 @@ PHP_FUNCTION(count) | ||
| switch (Z_TYPE_P(array)) { | ||
| case IS_NULL: | ||
| /* Intentionally not converted to an exception */ | ||
| php_error_docref(NULL, E_WARNING, "Parameter must be an array or an object that implements Countable"); | ||
| RETURN_LONG(0); | ||
| break; | ||
| @@ -799,11 +801,13 @@ PHP_FUNCTION(count) | ||
| } | ||
| /* If There's no handler and it doesn't implement Countable then add a warning */ | ||
| /* Intentionally not converted to an exception */ | ||
| php_error_docref(NULL, E_WARNING, "Parameter must be an array or an object that implements Countable"); | ||
| RETURN_LONG(1); | ||
| break; | ||
| } | ||
| default: | ||
| /* Intentionally not converted to an exception */ | ||
| php_error_docref(NULL, E_WARNING, "Parameter must be an array or an object that implements Countable"); | ||
| RETURN_LONG(1); | ||
| break; | ||
| @@ -5212,7 +5216,7 @@ static void php_array_diff(INTERNAL_FUNCTION_PARAMETERS, int behavior, int data_ | ||
| param_spec = "+f"; | ||
| diff_data_compare_func = php_array_user_compare; | ||
| } else { | ||
| php_error_docref(NULL, E_WARNING, "data_compare_type is %d. This should never happen. Please report as a bug", data_compare_type); | ||
| ZEND_ASSERT(0 && "Invalid data_compare_type"); | ||
| return; | ||
| } | ||
| @@ -6349,9 +6353,22 @@ PHP_FUNCTION(array_key_exists) | ||
| case IS_NULL: | ||
| RETVAL_BOOL(zend_hash_exists_ind(ht, ZSTR_EMPTY_ALLOC())); | ||
| break; | ||
| case IS_DOUBLE: | ||
kocsismate marked this conversation as resolved.
Outdated
Uh oh!There was an error while loading. Please reload this page. | ||
| RETVAL_BOOL(zend_hash_index_exists(ht, zend_dval_to_lval(Z_DVAL_P(key)))); | ||
| break; | ||
| case IS_FALSE: | ||
| RETVAL_BOOL(zend_hash_index_exists(ht, 0)); | ||
| break; | ||
| case IS_TRUE: | ||
| RETVAL_BOOL(zend_hash_index_exists(ht, 1)); | ||
| break; | ||
| case IS_RESOURCE: | ||
| zend_error(E_WARNING, "Resource ID#%d used as offset, casting to integer (%d)", Z_RES_HANDLE_P(key), Z_RES_HANDLE_P(key)); | ||
| RETVAL_BOOL(zend_hash_index_exists(ht, Z_RES_HANDLE_P(key))); | ||
| break; | ||
| default: | ||
| php_error_docref(NULL, E_WARNING, "The first argument should be either a string or an integer"); | ||
| RETVAL_FALSE; | ||
| zend_type_error("Illegal offset type"); | ||
| break; | ||
| } | ||
| } | ||
| /* }}} */ | ||
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.