forked from php/php-src
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Run autoloader only once for unqualified functions in a namespace
We bind the namespaced function to the global one if such a function exists.
- Loading branch information
Showing
6 changed files
with
95 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
--TEST-- | ||
Fallback to non-existent function triggers autoloading once in namespace, once in global. | ||
--FILE-- | ||
<?php | ||
|
||
namespace { | ||
function loader($name) { | ||
echo "function loader called with $name\n"; | ||
} | ||
|
||
autoload_register_function('loader'); | ||
} | ||
|
||
namespace bar { | ||
try { | ||
non_existent_function(); | ||
} | ||
catch (\Error $e) { | ||
echo "Error correctly caught: " . $e->getMessage() . "\n"; | ||
} | ||
} | ||
|
||
?> | ||
--EXPECT-- | ||
function loader called with bar\non_existent_function | ||
function loader called with non_existent_function | ||
Error correctly caught: Call to undefined function bar\non_existent_function() |
42 changes: 42 additions & 0 deletions
42
Zend/tests/autoloading/function/global_fallback_doesnt_repeat_autoloading.phpt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
--TEST-- | ||
Fallback to global function should trigger autoloading only once per namespace. | ||
--FILE-- | ||
<?php | ||
|
||
namespace { | ||
function loader($name) { | ||
echo "function loader called with $name\n"; | ||
} | ||
|
||
autoload_register_function('loader'); | ||
|
||
function foo() { | ||
echo "I am foo in global namespace.\n"; | ||
} | ||
} | ||
|
||
namespace bar { | ||
foo(); | ||
|
||
for ($i = 0; $i < 3; $i += 1) { | ||
foo(); | ||
} | ||
} | ||
namespace bar { | ||
foo(); | ||
} | ||
|
||
namespace Quux { | ||
foo(); | ||
} | ||
|
||
?> | ||
--EXPECT-- | ||
function loader called with bar\foo | ||
I am foo in global namespace. | ||
I am foo in global namespace. | ||
I am foo in global namespace. | ||
I am foo in global namespace. | ||
I am foo in global namespace. | ||
function loader called with Quux\foo | ||
I am foo in global namespace. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.