Skip to content

Commit c87e8b7

Browse files
committed
Add test that properly show cases the need for pining the function
If everything is in the same file the function cache will already have resolved the function pointer and not call the autoloader. However, this doesn't happen when the calls happen in different files.
1 parent 77310db commit c87e8b7

3 files changed

+39
-0
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?php
2+
namespace bar;
3+
4+
foo();
5+
6+
for ($i = 0; $i < 3; $i += 1) {
7+
foo();
8+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?php
2+
3+
namespace bar;
4+
5+
foo();
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
--TEST--
2+
Fallback to global function should trigger autoloading only once per namespace, seperate files case.
3+
--FILE--
4+
<?php
5+
6+
function loader($name) {
7+
echo "function loader called with $name\n";
8+
}
9+
10+
autoload_register_function('loader');
11+
12+
function foo() {
13+
echo "I am foo in global namespace.\n";
14+
}
15+
16+
include __DIR__ . DIRECTORY_SEPARATOR . 'global_fallback_doesnt_repeat_autoloading_file1.inc';
17+
include __DIR__ . DIRECTORY_SEPARATOR . 'global_fallback_doesnt_repeat_autoloading_file2.inc';
18+
19+
?>
20+
--EXPECT--
21+
function loader called with bar\foo
22+
I am foo in global namespace.
23+
I am foo in global namespace.
24+
I am foo in global namespace.
25+
I am foo in global namespace.
26+
I am foo in global namespace.

0 commit comments

Comments
 (0)