php-src/Zend/tests/bug31098.phpt
George Peter Banyard b2248789ed Implement 'Saner Numeric Strings' RFC:
RFC: https://wiki.php.net/rfc/saner-numeric-strings

This removes the -1 allow_error mode from is_numeric_string functions and replaces it by
a trailing boolean out argument to preserve BC in a couple of places.

Most of the changes can be resumed to "numeric" strings which emitted a E_NOTICE now emit
a E_WARNING and "numeric" strings which emitted a E_WARNING now throw a TypeError.

This mostly affects:
 - String offsets
 - Arithmetic operations
 - Bitwise operations

Closes GH-5762
2020-07-29 02:51:09 +01:00

65 lines
1.4 KiB
PHP

--TEST--
Bug #31098 (isset() / empty() incorrectly returns true in dereference of a wrong type)
--FILE--
<?php
$a = '';
var_dump(isset($a->b));
$a = 'a';
var_dump(isset($a->b));
$a = '0';
var_dump(isset($a->b));
$a = '';
var_dump(isset($a['b']));
$a = 'a';
var_dump(isset($a['b']));
$a = '0';
var_dump(isset($a['b']));
$simpleString = "Bogus String Text";
echo isset($simpleString->wrong)?"bug\n":"ok\n";
try {
echo isset($simpleString["wrong"])?"bug\n":"ok\n";
} catch (\TypeError $e) {
echo $e->getMessage() . \PHP_EOL;
}
echo isset($simpleString[-20])?"bug\n":"ok\n";
echo isset($simpleString[0])?"ok\n":"bug\n";
echo isset($simpleString["0"])?"ok\n":"bug\n";
echo isset($simpleString["16"])?"ok\n":"bug\n";
echo isset($simpleString["17"])?"bug\n":"ok\n";
echo $simpleString->wrong === null?"ok\n":"bug\n";
try {
echo $simpleString["wrong"] === "B"?"ok\n":"bug\n";
} catch (\TypeError $e) {
echo $e->getMessage() . \PHP_EOL;
}
echo $simpleString["0"] === "B"?"ok\n":"bug\n";
try {
$simpleString["wrong"] = "f";
} catch (\TypeError $e) {
echo $e->getMessage() . \PHP_EOL;
}
echo $simpleString["0"] === "f"?"ok\n":"bug\n";
?>
--EXPECTF--
bool(false)
bool(false)
bool(false)
bool(false)
bool(false)
bool(false)
ok
ok
ok
ok
ok
ok
ok
Warning: Attempt to read property "wrong" on string in %s on line %d
ok
Cannot access offset of type string on string
ok
Cannot access offset of type string on string
ok