|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2018-06-14 13:16 UTC] mark2011 at mayberg dot se
Description:
------------
Running the test script without opcache works fine. But with opcache enabled it results in an unexpected behaviour (after second execution). The test script below is extracted from a bigger library, I isolated a small test case.
PHP 7.2.6 is not yet available for my distro.
PHP 7.0, 7.1 does not show this error.
Test script:
---------------
<?php
echo "PHP ".PHP_VERSION." ".PHP_SAPI."<br>\n";
$token = "ABC";
$lengthBytes = strlenb($token);
echo "$token $lengthBytes ".($lengthBytes!=0 ? "ok" : "error")."<br>\n";
testString();
function testString()
{
$token = "ABC";
$lengthBytes = strlenb($token);
echo "$token $lengthBytes ".($lengthBytes!=0 ? "ok" : "error")."<br>\n";
}
function strlenb() { return call_user_func_array("strlen", func_get_args()); }
?>
Expected result:
----------------
PHP 7.2.5-0ubuntu0.18.04.1 apache2handler
ABC 3 ok
ABC 3 ok
Actual result:
--------------
PHP 7.2.5-0ubuntu0.18.04.1 apache2handler
ABC 3 ok
ABC error
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sun Oct 26 10:00:01 2025 UTC |
I can reproduce this with a pretty vanilla 7.2.6 under Archlinux. It can be simplified somewhat; this is also unstable (sometimes it returns 3, sometimes NULL): <?php t(); function t() { $l = strlenb("ABC"); var_dump($l); } function strlenb() { return call_user_func_array("strlen", func_get_args()); }This is a type-inference bug: strlenb: ; (lines=5, args=0, vars=0, tmps=1, ssa_vars=2, no_loops) ; (after dfa pass) ; /home/nikic/php-7.2/t001.php:10-10 ; return [null] BB0: start exit lines=[0-4] ; level=0 INIT_FCALL 0 80 string("strlen") #0.T0 [array [long] of [any]] = FUNC_GET_ARGS SEND_ARRAY 0 #0.T0 [array [long] of [any]] #1.V0 [null] = DO_FCALL RETURN #1.V0 [null] The return value of strlen() is determined to be null, which is wrong. The type is determined by zend_strlen_info(), which doesn't take the SEND_ARRAY into account properly. The same issue might also affect other custom inference functions. Btw, this particular one we can really just drop, because all useful cases are already handled by ZEND_STRLEN.