diff options
author | Nikita Popov <nikita.ppv@gmail.com> | 2019-12-09 15:14:39 +0100 |
---|---|---|
committer | Nikita Popov <nikita.ppv@gmail.com> | 2019-12-10 13:05:48 +0100 |
commit | 3f86adb0efab3a68d87645941dc997d1e6314050 (patch) | |
tree | 0e28ef40bbb487771fc0593766794bd14ed6e3a0 /ext/opcache/tests | |
parent | 4313659bb932737c31e0bfffa2410c501df2a2ff (diff) | |
download | php-git-3f86adb0efab3a68d87645941dc997d1e6314050.tar.gz |
Fixed bug #78935: Check that all linked classes can be preloaded
During preloading, check that all classes that have been included
as part of the preload script itself (rather than through opcache_compile_file)
can actually be preloaded, i.e. satisfy Windows restrictions, have
resolved initializers and resolved property types. When resolving
initializers and property types, also autoload additional classes.
Because of this, the resolution runs in a loop.
Diffstat (limited to 'ext/opcache/tests')
-rw-r--r-- | ext/opcache/tests/preload_004.phpt | 5 | ||||
-rw-r--r-- | ext/opcache/tests/preload_009.phpt | 4 | ||||
-rw-r--r-- | ext/opcache/tests/preload_loadable_classes_1.inc | 18 | ||||
-rw-r--r-- | ext/opcache/tests/preload_loadable_classes_1.phpt | 19 | ||||
-rw-r--r-- | ext/opcache/tests/preload_loadable_classes_2.inc | 6 | ||||
-rw-r--r-- | ext/opcache/tests/preload_loadable_classes_2.phpt | 17 | ||||
-rw-r--r-- | ext/opcache/tests/preload_loadable_classes_3.inc | 5 | ||||
-rw-r--r-- | ext/opcache/tests/preload_loadable_classes_3.phpt | 13 | ||||
-rw-r--r-- | ext/opcache/tests/preload_loadable_classes_4.inc | 3 | ||||
-rw-r--r-- | ext/opcache/tests/preload_loadable_classes_4.phpt | 16 | ||||
-rw-r--r-- | ext/opcache/tests/preload_unresolved_prop_type.inc | 2 | ||||
-rw-r--r-- | ext/opcache/tests/preload_unresolved_prop_type.phpt | 14 | ||||
-rw-r--r-- | ext/opcache/tests/preload_unresolved_prop_type_2.inc | 5 |
13 files changed, 123 insertions, 4 deletions
diff --git a/ext/opcache/tests/preload_004.phpt b/ext/opcache/tests/preload_004.phpt index 0441c78883..df92abdc28 100644 --- a/ext/opcache/tests/preload_004.phpt +++ b/ext/opcache/tests/preload_004.phpt @@ -12,5 +12,6 @@ opcache.preload={PWD}/preload_undef_const.inc var_dump(class_exists('Foo')); ?> --EXPECTF-- -Warning: Can't preload class Foo with unresolved initializer for constant A in %spreload_undef_const.inc on line 2 -bool(false) +Fatal error: Undefined class constant 'self::DOES_NOT_EXIST' in Unknown on line 0 + +Fatal error: Error generated while resolving initializers of class Foo during preloading in Unknown on line 0 diff --git a/ext/opcache/tests/preload_009.phpt b/ext/opcache/tests/preload_009.phpt index 84f444768c..1adbf5b006 100644 --- a/ext/opcache/tests/preload_009.phpt +++ b/ext/opcache/tests/preload_009.phpt @@ -13,6 +13,6 @@ var_dump(trait_exists('T')); var_dump(class_exists('Foo')); ?> --EXPECTF-- -Warning: Can't preload class Foo with unresolved initializer for constant C in %spreload_undef_const_2.inc on line 8 +Warning: Use of undefined constant UNDEF - assumed 'UNDEF' (this will throw an Error in a future version of PHP) in Unknown on line 0 +bool(true) bool(true) -bool(false) diff --git a/ext/opcache/tests/preload_loadable_classes_1.inc b/ext/opcache/tests/preload_loadable_classes_1.inc new file mode 100644 index 0000000000..b2bdabae1b --- /dev/null +++ b/ext/opcache/tests/preload_loadable_classes_1.inc @@ -0,0 +1,18 @@ +<?php + +spl_autoload_register(function($class) { + if ($class == 'Bar') { + class Bar { + const BAZ = 42; + + public self $x; + public Foo $y; + } + } else if ($class == 'Foo') { + class Foo {} + } +}); + +class Test { + const FOO = Bar::BAZ; +} diff --git a/ext/opcache/tests/preload_loadable_classes_1.phpt b/ext/opcache/tests/preload_loadable_classes_1.phpt new file mode 100644 index 0000000000..8673814403 --- /dev/null +++ b/ext/opcache/tests/preload_loadable_classes_1.phpt @@ -0,0 +1,19 @@ +--TEST-- +Preloading: Loadable class checking (1) +--INI-- +opcache.enable=1 +opcache.enable_cli=1 +opcache.optimization_level=-1 +opcache.preload={PWD}/preload_loadable_classes_1.inc +--SKIPIF-- +<?php require_once('skipif.inc'); ?> +--FILE-- +<?php +var_dump(class_exists('Test')); +var_dump(class_exists('Bar')); +var_dump(class_exists('Foo')); +?> +--EXPECT-- +bool(true) +bool(true) +bool(true) diff --git a/ext/opcache/tests/preload_loadable_classes_2.inc b/ext/opcache/tests/preload_loadable_classes_2.inc new file mode 100644 index 0000000000..d21384dcd4 --- /dev/null +++ b/ext/opcache/tests/preload_loadable_classes_2.inc @@ -0,0 +1,6 @@ +<?php + +class Test { + const X = UNDEF; + const Y = Foo::UNDEF; +} diff --git a/ext/opcache/tests/preload_loadable_classes_2.phpt b/ext/opcache/tests/preload_loadable_classes_2.phpt new file mode 100644 index 0000000000..4a5d2b8a66 --- /dev/null +++ b/ext/opcache/tests/preload_loadable_classes_2.phpt @@ -0,0 +1,17 @@ +--TEST-- +Preloading: Loadable class checking (2) +--INI-- +opcache.enable=1 +opcache.enable_cli=1 +opcache.optimization_level=-1 +opcache.preload={PWD}/preload_loadable_classes_2.inc +--SKIPIF-- +<?php require_once('skipif.inc'); ?> +--FILE-- +Unreachable +--EXPECTF-- +Warning: Use of undefined constant UNDEF - assumed 'UNDEF' (this will throw an Error in a future version of PHP) in Unknown on line 0 + +Fatal error: Class 'Foo' not found in Unknown on line 0 + +Fatal error: Error generated while resolving initializers of class Test during preloading in Unknown on line 0 diff --git a/ext/opcache/tests/preload_loadable_classes_3.inc b/ext/opcache/tests/preload_loadable_classes_3.inc new file mode 100644 index 0000000000..d5c550f8c4 --- /dev/null +++ b/ext/opcache/tests/preload_loadable_classes_3.inc @@ -0,0 +1,5 @@ +<?php + +class Test { + protected Foo $prop; +} diff --git a/ext/opcache/tests/preload_loadable_classes_3.phpt b/ext/opcache/tests/preload_loadable_classes_3.phpt new file mode 100644 index 0000000000..a48692960a --- /dev/null +++ b/ext/opcache/tests/preload_loadable_classes_3.phpt @@ -0,0 +1,13 @@ +--TEST-- +Preloading: Loadable class checking (3) +--INI-- +opcache.enable=1 +opcache.enable_cli=1 +opcache.optimization_level=-1 +opcache.preload={PWD}/preload_loadable_classes_3.inc +--SKIPIF-- +<?php require_once('skipif.inc'); ?> +--FILE-- +Unreachable +--EXPECTF-- +Fatal error: Failed to load class Foo used by typed property Test::$prop during preloading in Unknown on line 0 diff --git a/ext/opcache/tests/preload_loadable_classes_4.inc b/ext/opcache/tests/preload_loadable_classes_4.inc new file mode 100644 index 0000000000..162de6eab2 --- /dev/null +++ b/ext/opcache/tests/preload_loadable_classes_4.inc @@ -0,0 +1,3 @@ +<?php + +class Test extends Exception {} diff --git a/ext/opcache/tests/preload_loadable_classes_4.phpt b/ext/opcache/tests/preload_loadable_classes_4.phpt new file mode 100644 index 0000000000..07f0d094ce --- /dev/null +++ b/ext/opcache/tests/preload_loadable_classes_4.phpt @@ -0,0 +1,16 @@ +--TEST-- +Preloading: Loadable class checking (4) +--INI-- +opcache.enable=1 +opcache.enable_cli=1 +opcache.optimization_level=-1 +opcache.preload={PWD}/preload_loadable_classes_4.inc +--SKIPIF-- +<?php +require_once('skipif.inc'); +if (PHP_OS_FAMILY != 'Windows') die('skip Windows only'); +?> +--FILE-- +Unreachable +--EXPECTF-- +Fatal error: Class Test uses internal class Exception during preloading, which is not supported on Windows in Unknown on line 0 diff --git a/ext/opcache/tests/preload_unresolved_prop_type.inc b/ext/opcache/tests/preload_unresolved_prop_type.inc new file mode 100644 index 0000000000..05f4ee06a3 --- /dev/null +++ b/ext/opcache/tests/preload_unresolved_prop_type.inc @@ -0,0 +1,2 @@ +<?php +opcache_compile_file(__DIR__ . "/preload_unresolved_prop_type_2.inc"); diff --git a/ext/opcache/tests/preload_unresolved_prop_type.phpt b/ext/opcache/tests/preload_unresolved_prop_type.phpt new file mode 100644 index 0000000000..117f36692a --- /dev/null +++ b/ext/opcache/tests/preload_unresolved_prop_type.phpt @@ -0,0 +1,14 @@ +--TEST-- +Preload: Unresolved property type +--INI-- +opcache.enable=1 +opcache.enable_cli=1 +opcache.optimization_level=-1 +opcache.preload={PWD}/preload_unresolved_prop_type.inc +--SKIPIF-- +<?php require_once('skipif.inc'); ?> +--FILE-- +===DONE=== +--EXPECTF-- +Warning: Can't preload class Test with unresolved property types in %s on line %d +===DONE=== diff --git a/ext/opcache/tests/preload_unresolved_prop_type_2.inc b/ext/opcache/tests/preload_unresolved_prop_type_2.inc new file mode 100644 index 0000000000..c5557d1117 --- /dev/null +++ b/ext/opcache/tests/preload_unresolved_prop_type_2.inc @@ -0,0 +1,5 @@ +<?php + +class Test { + public Unknown $prop; +} |