com php-src: Print more precise warning for unresolved constants: ext/opcache/ZendAccelerator.c ext/opcache/tests/preload_0 04.phpt
ext/opcache/tests/preload_009.phpt

From: Date: Thu, 21 Feb 2019 09:35:59 +0000
Subject: com php-src: Print more precise warning for unresolved constants: ext/opcache/ZendAccelerator.c ext/opcache/tests/preload_0 04.phpt
ext/opcache/tests/preload_009.phpt
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-104793@lists.php.net to get a copy of this message
Commit: 0989b7001597fe59e54109ce2839bbfa8d041f2d Author: Nikita Popov <nikita.ppv@gmail.com> Thu, 21 Feb 2019 10:35:59 +0100 Parents: 67682356fba0405b1c75d7ae199f7beda82fbf84 Branches: PHP-7.4 master Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=0989b7001597fe59e54109ce2839bbfa8d041f2d Log: Print more precise warning for unresolved constants Changed paths: M ext/opcache/ZendAccelerator.c M ext/opcache/tests/preload_004.phpt M ext/opcache/tests/preload_009.phpt Diff: diff --git a/ext/opcache/ZendAccelerator.c b/ext/opcache/ZendAccelerator.c index ff76eb9..5c05afc 100644 --- a/ext/opcache/ZendAccelerator.c +++ b/ext/opcache/ZendAccelerator.c @@ -3258,6 +3258,34 @@ try_again: } } +static void get_unresolved_initializer(zend_class_entry *ce, const char **kind, const char **name) { + zend_string *key; + zend_class_constant *c; + zend_property_info *prop; + + *kind = "unknown"; + *name = ""; + + ZEND_HASH_FOREACH_STR_KEY_PTR(&ce->constants_table, key, c) { + if (Z_TYPE(c->value) == IS_CONSTANT_AST) { + *kind = "constant "; + *name = ZSTR_VAL(key); + } + } ZEND_HASH_FOREACH_END(); + ZEND_HASH_FOREACH_STR_KEY_PTR(&ce->properties_info, key, prop) { + zval *val; + if (prop->flags & ZEND_ACC_STATIC) { + val = &ce->default_static_members_table[OBJ_PROP_TO_NUM(prop->offset)]; + } else { + val = &ce->default_properties_table[OBJ_PROP_TO_NUM(prop->offset)]; + } + if (Z_TYPE_P(val) == IS_CONSTANT_AST) { + *kind = (prop->flags & ZEND_ACC_STATIC) ? "static property $" : "property $"; + *name = ZSTR_VAL(key); + } + } ZEND_HASH_FOREACH_END(); +} + static void preload_link(void) { zval *zv; @@ -3479,7 +3507,9 @@ static void preload_link(void) } zend_string_release(key); } else if (!(ce->ce_flags & ZEND_ACC_CONSTANTS_UPDATED)) { - 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); + const char *kind, *name; + get_unresolved_initializer(ce, &kind, &name); + zend_error(E_WARNING, "Can't preload class %s with unresolved initializer for %s%s at %s:%d", ZSTR_VAL(ce->name), kind, 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", ZSTR_VAL(ce->name), ZSTR_VAL(ce->info.user.filename), ce->info.user.line_start); } else { diff --git a/ext/opcache/tests/preload_004.phpt b/ext/opcache/tests/preload_004.phpt index eed7378..690d7f8 100644 --- a/ext/opcache/tests/preload_004.phpt +++ b/ext/opcache/tests/preload_004.phpt @@ -12,5 +12,5 @@ opcache.preload={PWD}/preload_undef_const.inc var_dump(class_exists('Foo')); ?> --EXPECTF-- -Warning: Can't preload class Foo with unresolved constants at %s:%d in Unknown on line 0 +Warning: Can't preload class Foo with unresolved initializer for constant A at %s:%d in Unknown on line 0 bool(false) diff --git a/ext/opcache/tests/preload_009.phpt b/ext/opcache/tests/preload_009..phpt index 563e010..21c4766 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 constants at %s:%d in Unknown on line 0 +Warning: Can't preload class Foo with unresolved initializer for constant C at %s:%d in Unknown on line 0 bool(true) bool(false)

« previous php.cvs (#104793) next »