mirror of
https://github.com/php/php-src.git
synced 2026-03-24 00:02:20 +01:00
This solely affects the builtin enum functions currently. Given that these are stored in SHM, we cannot simply hardwire a pointer into the internal function runtime cache on NTS too, but have to use a MAP_PTR (like on ZTS). Now, by design, the runtime cache of internal functions no longer is reset between requests, hence we need to store them explicitly as static runtime cache. On NTS builds we cannot trivially move the pointers into CG(internal_run_time_cache) as they're directly stored on the individual functions (on ZTS we could simply iterate the static map_ptrs). Hence, we have the choice between having opcache managing the internal run_time_cache for its preloaded functions itself or realloc CG(internal_run_time_cache) and iterate through all functions to assign the new address. We choose the latter for simplicity and initial speed.
56 lines
1.1 KiB
PHP
56 lines
1.1 KiB
PHP
--TEST--
|
|
Enum preloading with observers
|
|
--EXTENSIONS--
|
|
opcache
|
|
zend_test
|
|
--INI--
|
|
opcache.enable=1
|
|
opcache.enable_cli=1
|
|
opcache.optimization_level=-1
|
|
opcache.preload={PWD}/preload_enum.inc
|
|
zend_test.observer.enabled=1
|
|
zend_test.observer.show_output=1
|
|
zend_test.observer.observe_all=1
|
|
--SKIPIF--
|
|
<?php
|
|
if (PHP_OS_FAMILY == 'Windows') die('skip Preloading is not supported on Windows');
|
|
?>
|
|
--FILE--
|
|
<?php
|
|
|
|
spl_autoload_register(static function ($class) {
|
|
if ($class === 'MyEnum') {
|
|
require_once(__DIR__ . '/preload_enum.inc');
|
|
}
|
|
});
|
|
|
|
var_dump(MyEnum::cases());
|
|
|
|
?>
|
|
--EXPECTF--
|
|
<!-- init '%spreload_enum.inc' -->
|
|
<file '%spreload_enum.inc'>
|
|
<!-- init var_dump() -->
|
|
<var_dump>
|
|
enum(MyEnum::Bar)
|
|
</var_dump>
|
|
</file '%spreload_enum.inc'>
|
|
<!-- init '%spreload_enum_observed.php' -->
|
|
<file '%spreload_enum_observed.php'>
|
|
<!-- init spl_autoload_register() -->
|
|
<spl_autoload_register>
|
|
</spl_autoload_register>
|
|
<!-- init MyEnum::cases() -->
|
|
<MyEnum::cases>
|
|
</MyEnum::cases>
|
|
<!-- init var_dump() -->
|
|
<var_dump>
|
|
array(2) {
|
|
[0]=>
|
|
enum(MyEnum::Foo)
|
|
[1]=>
|
|
enum(MyEnum::Bar)
|
|
}
|
|
</var_dump>
|
|
</file '%spreload_enum_observed.php'>
|