php-src/Zend/tests/eval_constant_resolution.phpt
Tyson Andre 4c48fd22d7
Fix inconsistency in true/false/null constant resolution when opcache is not used (#7441)
Strangely, uses of eval and 'php -a' (or loading a file without opcache after a namespaced constant was declared)
will not treat non-FQ true/false/null as magic keywords, while compiled php required from a file would do that.

This may confuse people learning the language, and result in code loaded with
eval() behaving differently from the same snippet in a file loaded by require.

```
Interactive shell

php > define('foo\true', 'test');
php > namespace foo { var_dump(true); }
string(4) "test"
```

This will make the same session instead properly emit `bool(true);` like it
already would if running those statements in files when opcache was used.
2021-09-03 08:42:36 -04:00

23 lines
449 B
PHP

--TEST--
eval() constant resolution
--FILE--
<?php
namespace foo {
define('foo\true', 'test');
echo "In eval\n";
eval('namespace foo { var_dump(true); var_dump(TrUe); var_dump(namespace\true); var_dump(\true); }');
echo "Outside eval\n";
var_dump(true); var_dump(TrUe); var_dump(namespace\true); var_dump(\true);
}
?>
--EXPECT--
In eval
bool(true)
bool(true)
string(4) "test"
bool(true)
Outside eval
bool(true)
bool(true)
string(4) "test"
bool(true)