]> granicus.if.org Git - php/commitdiff
Suppress zend_throw_error during preload constant resolution
authorNikita Popov <nikita.ppv@gmail.com>
Fri, 15 Feb 2019 12:03:46 +0000 (13:03 +0100)
committerNikita Popov <nikita.ppv@gmail.com>
Fri, 15 Feb 2019 12:03:46 +0000 (13:03 +0100)
Related to bug #77615.

Zend/zend.c
ext/opcache/ZendAccelerator.c
ext/opcache/tests/preload_004.phpt [new file with mode: 0644]
ext/opcache/tests/preload_undef_const.inc [new file with mode: 0644]

index 6dc1c9c4cccb0ee060c684384f4969a709baedcf..f3d501f7e1c83af21a0df46f9bb94cd0f8ae1b34 100644 (file)
@@ -1503,6 +1503,11 @@ ZEND_API ZEND_COLD void zend_throw_error(zend_class_entry *exception_ce, const c
                exception_ce = zend_ce_error;
        }
 
+       /* Marker used to disable exception generation during preloading. */
+       if (EG(exception) == (void*)(uintptr_t)-1) {
+               return;
+       }
+
        va_start(va, format);
        zend_vspprintf(&message, 0, format, va);
 
index 303034a4ba9fd63c9f992061e82ecaee1a18435b..985c66c32e651440e0f017f2a871c09bb0b7266d 100644 (file)
@@ -3453,11 +3453,11 @@ static void preload_link(void)
                        break;
                }
                if (!(ce->ce_flags & ZEND_ACC_LINKED)) {
-                       zend_error(E_WARNING, "Can't preload unlinked class  %s at %s:%d\n", ZSTR_VAL(ce->name), ZSTR_VAL(ce->info.user.filename), ce->info.user.line_start);
+                       zend_error(E_WARNING, "Can't preload unlinked class  %s at %s:%d", ZSTR_VAL(ce->name), ZSTR_VAL(ce->info.user.filename), ce->info.user.line_start);
                } else if (!(ce->ce_flags & ZEND_ACC_CONSTANTS_UPDATED)) {
-                       zend_error(E_WARNING, "Can't preload class %s with unresolved constants at %s:%d\n", ZSTR_VAL(ce->name), ZSTR_VAL(ce->info.user.filename), ce->info.user.line_start);
+                       zend_error(E_WARNING, "Can't preload class %s with unresolved constants at %s:%d", ZSTR_VAL(ce->name), ZSTR_VAL(ce->info.user.filename), ce->info.user.line_start);
                } else if (!(ce->ce_flags & ZEND_ACC_PROPERTY_TYPES_RESOLVED)) {
-                       zend_error(E_WARNING, "Can't preload class %s with unresolved property types at %s:%d\n", ZSTR_VAL(ce->name), ZSTR_VAL(ce->info.user.filename), ce->info.user.line_start);
+                       zend_error(E_WARNING, "Can't preload class %s with unresolved property types at %s:%d", ZSTR_VAL(ce->name), ZSTR_VAL(ce->info.user.filename), ce->info.user.line_start);
                } else {
                        continue;
                }
diff --git a/ext/opcache/tests/preload_004.phpt b/ext/opcache/tests/preload_004.phpt
new file mode 100644 (file)
index 0000000..eed7378
--- /dev/null
@@ -0,0 +1,16 @@
+--TEST--
+Preloading class with undefined class constant access
+--INI--
+opcache.enable=1
+opcache.enable_cli=1
+opcache.optimization_level=-1
+opcache.preload={PWD}/preload_undef_const.inc
+--SKIPIF--
+<?php require_once('skipif.inc'); ?>
+--FILE--
+<?php
+var_dump(class_exists('Foo'));
+?>
+--EXPECTF--
+Warning: Can't preload class Foo with unresolved constants at %s:%d in Unknown on line 0
+bool(false)
diff --git a/ext/opcache/tests/preload_undef_const.inc b/ext/opcache/tests/preload_undef_const.inc
new file mode 100644 (file)
index 0000000..8d199e0
--- /dev/null
@@ -0,0 +1,4 @@
+<?php
+class Foo {
+    const A = self::DOES_NOT_EXIST;
+}