com php-src: Suppress zend_throw_error during preload constant resolution: Zend/zend.c ext/opcache/ZendA ccelerator.c
ext/opcache/tests/preload_004.phpt ext/opcache/tests/preload_undef_const.inc
| From: | Nikita Popov | Date: | Fri, 15 Feb 2019 12:03:46 +0000 |
| Subject: | com php-src: Suppress zend_throw_error during preload constant resolution: Zend/zend.c ext/opcache/ZendA ccelerator.c ext/opcache/tests/preload_004.phpt ext/opcache/tests/preload_undef_const.inc |
||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-104658@lists.php.net to get a copy of this message | ||
Commit: ade9d5e95b879def3ce5b2b0c117ce1258c211ee
Author: Nikita Popov <nikita.ppv@gmail.com> Fri, 15 Feb 2019 13:03:46 +0100
Parents: c15007956d9fbee7d8ef862cb222469382e257ae
Branches: PHP-7.4 master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=ade9d5e95b879def3ce5b2b0c117ce1258c211ee
Log:
Suppress zend_throw_error during preload constant resolution
Related to bug #77615.
Bugs:
https://bugs.php.net/77615
Changed paths:
M Zend/zend.c
M ext/opcache/ZendAccelerator.c
A ext/opcache/tests/preload_004.phpt
A ext/opcache/tests/preload_undef_const.inc
Diff:
diff --git a/Zend/zend.c b/Zend/zend.c
index 6dc1c9c..f3d501f 100644
--- a/Zend/zend.c
+++ b/Zend/zend.c
@@ -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);
diff --git a/ext/opcache/ZendAccelerator.c b/ext/opcache/ZendAccelerator.c
index 303034a..985c66c 100644
--- a/ext/opcache/ZendAccelerator.c
+++ b/ext/opcache/ZendAccelerator.c
@@ -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
index 0000000...eed7378
--- /dev/null
+++ b/ext/opcache/tests/preload_004.phpt
@@ -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
index 0000000..8d199e0
--- /dev/null
+++ b/ext/opcache/tests/preload_undef_const.inc
@@ -0,0 +1,4 @@
+<?php
+class Foo {
+ const A = self::DOES_NOT_EXIST;
+}