com php-src: Support for type checks of named constants in property default values.: Zend/tests/type_declarations/typed_properties_ 058.phpt
Zend/zend_API.c
| From: | Bob Weinand | Date: | Wed, 25 May 2016 20:17:56 +0000 |
| Subject: | com php-src: Support for type checks of named constants in property default values.: Zend/tests/type_declarations/typed_properties_ 058.phpt Zend/zend_API.c |
||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-95525@lists.php.net to get a copy of this message | ||
Commit: c304c6b761577aad02ea1555a43ffe2920fb16f8
Author: Dmitry Stogov <dmitry@zend.com> Wed, 25 May 2016 23:17:56 +0300
Parents: 2019f660d47b3b034a4485f0ff8c3a02b800409d
Branches: typed_ref_properties
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=c304c6b761577aad02ea1555a43ffe2920fb16f8
Log:
Support for type checks of named constants in property default values.
Changed paths:
M Zend/tests/type_declarations/typed_properties_058.phpt
M Zend/zend_API.c
Diff:
diff --git a/Zend/tests/type_declarations/typed_properties_058.phpt
b/Zend/tests/type_declarations/typed_properties_058.phpt
index 18fae53..2be5aa7 100644
--- a/Zend/tests/type_declarations/typed_properties_058.phpt
+++ b/Zend/tests/type_declarations/typed_properties_058.phpt
@@ -21,13 +21,17 @@ try {
echo $e->getMessage() . "\n";
}
-try {
- $o = new B();
- var_dump($o->foo);
-} catch (Throwable $e) {
- echo $e->getMessage() . "\n";
+for ($i = 0; $i < 2; $i++) {
+ try {
+ $o = new B();
+ var_dump($o->foo);
+ } catch (Throwable $e) {
+ echo $e->getMessage() . "\n";
+ }
}
?>
--EXPECT--
int(5)
Typed property B::$foo must be string, integer used
+Typed property B::$foo must be string, integer used
+
diff --git a/Zend/zend_API.c b/Zend/zend_API.c
index 799d462..379f8c4 100644
--- a/Zend/zend_API.c
+++ b/Zend/zend_API.c
@@ -1087,6 +1087,7 @@ ZEND_API int zend_update_class_constants(zend_class_entry *class_type) /* {{{
*/
if (class_type->parent) {
if (UNEXPECTED(zend_update_class_constants(class_type->parent) != SUCCESS)) {
+ class_type->ce_flags &= ~ZEND_ACC_CONSTANTS_UPDATED;
return FAILURE;
}
}
@@ -1144,19 +1145,24 @@ ZEND_API int zend_update_class_constants(zend_class_entry *class_type) /*
{{{ */
}
ZVAL_DEREF(val);
if (Z_CONSTANT_P(val)) {
- if (UNEXPECTED(zval_update_constant_ex(val, ce) != SUCCESS)) {
- return FAILURE;
- }
if (prop_info->type) {
- zval tmp, *v;
+ zval tmp, tmp2, *v;
- v = zend_verify_property_type(prop_info, val, &tmp,
ZEND_CALL_USES_STRICT_TYPES(EG(current_execute_data)));
+ ZVAL_COPY(&tmp, val);
+ if (UNEXPECTED(zval_update_constant_ex(&tmp, ce) != SUCCESS)) {
+ return FAILURE;
+ }
+ v = zend_verify_property_type(prop_info, &tmp, &tmp2,
ZEND_CALL_USES_STRICT_TYPES(EG(current_execute_data)));
if (UNEXPECTED(!v)) {
- zend_verify_property_type_error(prop_info, prop_info->name, val);
+ zend_verify_property_type_error(prop_info, prop_info->name, &tmp);
+ class_type->ce_flags &= ~ZEND_ACC_CONSTANTS_UPDATED;
+ zval_ptr_dtor(&tmp);
return FAILURE;
- } else if (val != v) {
- ZVAL_COPY_VALUE(val, v);
}
+ zval_ptr_dtor(val);
+ ZVAL_COPY_VALUE(val, v);
+ } else if (UNEXPECTED(zval_update_constant_ex(val, ce) != SUCCESS)) {
+ return FAILURE;
}
}
}