php-src/Zend/tests/isset_array.phpt
Máté Kocsis 14bdb0cfc7 Fix consistency issues with array accesses warnings/exceptions
* Change a number of "resource used as offset" notices to warnings,
   which were previously missed.
 * Throw the "resource used as offset" warning for isset() as well.
 * Make array_key_exists() behavior with regard to different key
   types consistent with isset() and normal array accesses. All key
   types now use the usual coercions and array/object keys throw
   TypeError.

Closes GH-4887.
2019-11-06 12:56:47 +01:00

49 lines
797 B
PHP

--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