-
Notifications
You must be signed in to change notification settings - Fork 7.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement delayed early binding for classes without parents
Normally, we add classes without parents (and no interfaces or traits) directly to the class map, early binding the class. However, if the same class has already been registered, we would instead just add a ZEND_DECLARE_CLASS instruction and let the handler throw a duplicate class declaration exception. However, with opcache, if on the next request the files are included in the opposite order, we won't perform early binding. To fix this, create a ZEND_DECLARE_CLASS_DELAYED instruction instead and handle classes without parents accordingly, skipping any linking for classes that are already linked in delayed early binding. Fixes GH-8846
- Loading branch information
Showing
7 changed files
with
74 additions
and
5 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
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,4 @@ | ||
<?php | ||
class Foo { | ||
const BAR = true; | ||
} |
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,5 @@ | ||
<?php | ||
var_dump(Foo::BAR); | ||
class Foo { | ||
const BAR = true; | ||
} |
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,39 @@ | ||
--TEST-- | ||
Bug GH-8846: Delayed early binding can be used for classes without parents | ||
--EXTENSIONS-- | ||
opcache | ||
--CONFLICTS-- | ||
server | ||
--INI-- | ||
opcache.validate_timestamps=1 | ||
opcache.revalidate_freq=0 | ||
--FILE-- | ||
<?php | ||
|
||
file_put_contents(__DIR__ . '/gh8846-index.php', <<<'PHP' | ||
<?php | ||
if (!@$_GET['skip']) { | ||
include __DIR__ . '/gh8846-1.inc'; | ||
} | ||
include __DIR__ . '/gh8846-2.inc'; | ||
echo "Ok\n"; | ||
PHP); | ||
|
||
include 'php_cli_server.inc'; | ||
php_cli_server_start('-d opcache.enable=1 -d opcache.enable_cli=1'); | ||
|
||
echo file_get_contents('http://' . PHP_CLI_SERVER_ADDRESS . '/gh8846-index.php'); | ||
echo "\n"; | ||
echo file_get_contents('http://' . PHP_CLI_SERVER_ADDRESS . '/gh8846-index.php?skip=1'); | ||
?> | ||
--CLEAN-- | ||
<?php | ||
@unlink(__DIR__ . '/gh8846-index.php'); | ||
?> | ||
--EXPECTF-- | ||
bool(true) | ||
<br /> | ||
<b>Fatal error</b>: Cannot declare class Foo, because the name is already in use in <b>%sgh8846-2.inc</b> on line <b>%d</b><br /> | ||
|
||
bool(true) | ||
Ok |
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