-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Open
Milestone
Description
Description
The following code:
a.php
:
<?php
set_error_handler(function (int $errno, string $msg) {
require __DIR__.'/b.php';
echo 'error handler called: ', $msg;
});
$code = '<?php (double) $x;';
$tokens = token_get_all($code, \TOKEN_PARSE);
echo "\n\n";
foreach ($tokens as $token) {
if (is_string($token)) {
echo $token, "\n";
} else {
echo token_name($token[0]) . ' "' . $token[1], "\"\n";
}
}
b.php
:
<?php 1;
Calling php a.php
resulted in this output:
error handler called: Non-canonical cast (double) is deprecated, use the (float) cast instead
T_OPEN_TAG "<?php "
T_OPEN_TAG "<?php "
T_LNUMBER "1"
;
T_WHITESPACE "
"
T_DOUBLE_CAST "(double)"
T_WHITESPACE " "
T_VARIABLE "$x"
;
But I expected this output instead:
error handler called: Non-canonical cast (double) is deprecated, use the (float) cast instead
T_OPEN_TAG "<?php "
T_DOUBLE_CAST "(double)"
T_WHITESPACE " "
T_VARIABLE "$x"
;
Not sure about the error handler call. Is it intended that the error handler is called for deprecations inside the code given to token_get_all
?
But at least I do not expect to get the tokens of b.php
inside the tokens of the code given to token_get_all
.
PHP Version
PHP 8.5.0-dev (cli) (built: Aug 16 2025 23:33:23) (NTS)
Copyright (c) The PHP Group
Built by Shivam Mathur
Zend Engine v4.5.0-dev, Copyright (c) Zend Technologies
with Zend OPcache v8.5.0-dev, Copyright (c), by Zend Technologies
Operating System
macOS