-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix Class "X" not found due to coroutine context switching in autoload (
#5180) * Fix Class "X" not found due to coroutine context switching in autoload * Fix * Fix * Support coroutine switch in autoload * Update * Add test * Fix * fix test name * Fix * fix * optimize * optimize
- Loading branch information
Showing
7 changed files
with
185 additions
and
0 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,2 @@ | ||
<?php | ||
new SwooleTestClassA2(); |
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,32 @@ | ||
--TEST-- | ||
swoole_coroutine: autoload | ||
--SKIPIF-- | ||
<?php | ||
require __DIR__ . '/../include/skipif.inc'; | ||
?> | ||
--FILE-- | ||
<?php | ||
require __DIR__ . '/../include/bootstrap.php'; | ||
|
||
spl_autoload_register(function ($class) { | ||
co::sleep(0.001); // coroutine context switch | ||
if ($class == 'SwooleTestClassA') { | ||
require TESTS_ROOT_PATH . '/include/api/test_classes/A.php'; | ||
} | ||
}); | ||
|
||
Swoole\Coroutine\run(function () { | ||
for ($i = 0; $i < 2; ++$i) | ||
{ | ||
go(static function (): void { | ||
var_dump(new SwooleTestClassA()); | ||
}); | ||
} | ||
}); | ||
|
||
?> | ||
--EXPECTF-- | ||
object(SwooleTestClassA)#%d (0) { | ||
} | ||
object(SwooleTestClassA)#%d (0) { | ||
} |
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,28 @@ | ||
--TEST-- | ||
swoole_coroutine: autoload not found | ||
--SKIPIF-- | ||
<?php | ||
require __DIR__ . '/../include/skipif.inc'; | ||
?> | ||
--FILE-- | ||
<?php | ||
require __DIR__ . '/../include/bootstrap.php'; | ||
|
||
spl_autoload_register(function ($class) { | ||
if ($class == 'SwooleTestClassA2') { | ||
require TESTS_ROOT_PATH . '/include/api/test_classes/A2.php'; | ||
} | ||
}); | ||
|
||
Co\run( function() { | ||
var_dump(new SwooleTestClassA2()); | ||
}); | ||
?> | ||
--EXPECTF-- | ||
Fatal error: Uncaught Error: Class "SwooleTestClassA2" not found in %s:%d | ||
Stack trace: | ||
#0 %s(%d): %s | ||
#1 %s(%d): %s | ||
#2 [internal function]: {closure}() | ||
#3 {main} | ||
thrown in %s on line %d |
26 changes: 26 additions & 0 deletions
26
tests/swoole_coroutine/autoload_not_found_not_in_coroutine.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,26 @@ | ||
--TEST-- | ||
swoole_coroutine: autoload not found and not in coroutine | ||
--SKIPIF-- | ||
<?php | ||
require __DIR__ . '/../include/skipif.inc'; | ||
?> | ||
--FILE-- | ||
<?php | ||
require __DIR__ . '/../include/bootstrap.php'; | ||
|
||
spl_autoload_register(function ($class) { | ||
if ($class == 'SwooleTestClassA2') { | ||
require TESTS_ROOT_PATH . '/include/api/test_classes/A2.php'; | ||
} | ||
}); | ||
|
||
var_dump(new SwooleTestClassA2()); | ||
|
||
?> | ||
--EXPECTF-- | ||
Fatal error: Uncaught Error: Class "SwooleTestClassA2" not found in %s:%d | ||
Stack trace: | ||
#0 %s(%d): %s | ||
#1 %s(%d): %s | ||
#2 {main} | ||
thrown in %s on line %d |
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,25 @@ | ||
--TEST-- | ||
swoole_coroutine: autoload not in coroutine | ||
--SKIPIF-- | ||
<?php | ||
require __DIR__ . '/../include/skipif.inc'; | ||
?> | ||
--FILE-- | ||
<?php | ||
require __DIR__ . '/../include/bootstrap.php'; | ||
|
||
spl_autoload_register(function ($class) { | ||
if ($class == 'SwooleTestClassA') { | ||
require TESTS_ROOT_PATH . '/include/api/test_classes/A.php'; | ||
} | ||
}); | ||
|
||
var_dump(new SwooleTestClassA()); | ||
var_dump(new SwooleTestClassA()); | ||
|
||
?> | ||
--EXPECTF-- | ||
object(SwooleTestClassA)#%d (0) { | ||
} | ||
object(SwooleTestClassA)#%d (0) { | ||
} |