|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2018-08-23 23:40 UTC] Wes dot example at example dot org
[2018-08-24 00:19 UTC] levim@php.net
[2018-08-24 08:52 UTC] syl dot fabre at gmail dot com
[2018-08-24 09:09 UTC] syl dot fabre at gmail dot com
-Operating System: ubuntu 16.04
+Operating System: eval.org
-PHP Version: 7.1.21
+PHP Version: 7.3.0-beta2
[2018-08-24 09:09 UTC] syl dot fabre at gmail dot com
[2018-08-24 09:59 UTC] nikic@php.net
-Status: Open
+Status: Duplicate
[2018-08-24 09:59 UTC] nikic@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sun Nov 02 03:00:01 2025 UTC |
Description: ------------ PHP 7.1.20-1+ubuntu16.04.1+deb.sury.org+1 (cli) (built: Jul 25 2018 10:06:40) ( NTS ) I don't have access to the latest update 7.1.21 The namespace resolution for a function seems to be cached somehow: if you call a function, then eval code to override the function in a namespace then the evaled code won't be run. If you don't call the function before evaling the code, then it's run. Test script: --------------- run php test2.php with the line commented run php test2.php without the line commented # test.php <?php namespace Test; Class Hello { public function test() { var_dump('unqualified:' . time()); if(function_exists('\Test\time')){ var_dump('fully-qualified:' . \Test\time()); } else{ var_dump('fully-qualified:not found'); } } } # test2.php <?php include __DIR__ . '/test.php'; $test = new Test\Hello(); $test->test(); // toggle comment this line eval(' namespace Test; function time(){return \'foo\';} '); $test->test(); Expected result: ---------------- with the line commented: string(15) "unqualified:foo" string(19) "fully-qualified:foo" with the line uncommented: string(22) "unqualified:1535066193" string(25) "fully-qualified:not found" string(22) "unqualified:foo" string(19) "fully-qualified:foo" Actual result: -------------- with the line commented: string(15) "unqualified:foo" string(19) "fully-qualified:foo" with the line uncommented: string(22) "unqualified:1535066193" string(25) "fully-qualified:not found" string(22) "unqualified:1535066193" string(19) "fully-qualified:foo"