From 008bfcc7ba7b47df4e4f6a920a299fdb58295e57 Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Fri, 14 May 2021 14:47:40 +0200 Subject: [PATCH] Use NO_DYNAMIC_PROPERTIES for Closure Instead of manually implementing this, use the standard mechanism. This has minor behavior changes (e.g. doing an isset() will now return false instead of throwing) which are more in line with typical behavior. --- Zend/tests/bug50146.phpt | 8 ++---- Zend/tests/closure_022.phpt | 2 +- Zend/tests/closure_031.phpt | 5 ++-- Zend/tests/closure_write_prop.phpt | 2 +- Zend/zend_closures.c | 46 ------------------------------ Zend/zend_closures.stub.php | 1 + Zend/zend_closures_arginfo.h | 4 +-- 7 files changed, 10 insertions(+), 58 deletions(-) diff --git a/Zend/tests/bug50146.phpt b/Zend/tests/bug50146.phpt index 0ef9048b061..3d3b54ffc1e 100644 --- a/Zend/tests/bug50146.phpt +++ b/Zend/tests/bug50146.phpt @@ -13,11 +13,7 @@ var_dump($ref->hasProperty('b')); var_dump(isset($obj->a)); ?> ---EXPECTF-- +--EXPECT-- +bool(false) bool(false) bool(false) - -Fatal error: Uncaught Error: Closure object cannot have properties in %s:%d -Stack trace: -#0 {main} - thrown in %s on line %d diff --git a/Zend/tests/closure_022.phpt b/Zend/tests/closure_022.phpt index 8977e963dfa..8e0fd06c1d3 100644 --- a/Zend/tests/closure_022.phpt +++ b/Zend/tests/closure_022.phpt @@ -8,7 +8,7 @@ $foo = function() use ($a) { $foo->a = 1; ?> --EXPECTF-- -Fatal error: Uncaught Error: Closure object cannot have properties in %sclosure_022.php:5 +Fatal error: Uncaught Error: Cannot create dynamic property Closure::$a in %s:%d Stack trace: #0 {main} thrown in %sclosure_022.php on line 5 diff --git a/Zend/tests/closure_031.phpt b/Zend/tests/closure_031.phpt index e757f677488..19f3dc6e321 100644 --- a/Zend/tests/closure_031.phpt +++ b/Zend/tests/closure_031.phpt @@ -3,7 +3,7 @@ Closure 031: Closure properties with custom error handlers --FILE-- --EXPECT-- -Error: Closure object cannot have properties +Warning: Undefined property: Closure::$a +NULL diff --git a/Zend/tests/closure_write_prop.phpt b/Zend/tests/closure_write_prop.phpt index 38bebf4e1b7..8dbf18e6704 100644 --- a/Zend/tests/closure_write_prop.phpt +++ b/Zend/tests/closure_write_prop.phpt @@ -19,4 +19,4 @@ try { ?> --EXPECT-- -Closure object cannot have properties +Cannot create dynamic property Closure::$b diff --git a/Zend/zend_closures.c b/Zend/zend_closures.c index 52d5c5d1ba0..ad8e68b9c8f 100644 --- a/Zend/zend_closures.c +++ b/Zend/zend_closures.c @@ -28,11 +28,6 @@ #include "zend_globals.h" #include "zend_closures_arginfo.h" -#define ZEND_CLOSURE_PRINT_NAME "Closure object" - -#define ZEND_CLOSURE_PROPERTY_ERROR() \ - zend_throw_error(NULL, "Closure object cannot have properties") - typedef struct _zend_closure { zend_object std; zend_function func; @@ -442,42 +437,6 @@ static zend_function *zend_closure_get_method(zend_object **object, zend_string } /* }}} */ -static ZEND_COLD zval *zend_closure_read_property(zend_object *object, zend_string *member, int type, void **cache_slot, zval *rv) /* {{{ */ -{ - ZEND_CLOSURE_PROPERTY_ERROR(); - return &EG(uninitialized_zval); -} -/* }}} */ - -static ZEND_COLD zval *zend_closure_write_property(zend_object *object, zend_string *member, zval *value, void **cache_slot) /* {{{ */ -{ - ZEND_CLOSURE_PROPERTY_ERROR(); - return &EG(error_zval); -} -/* }}} */ - -static ZEND_COLD zval *zend_closure_get_property_ptr_ptr(zend_object *object, zend_string *member, int type, void **cache_slot) /* {{{ */ -{ - ZEND_CLOSURE_PROPERTY_ERROR(); - return NULL; -} -/* }}} */ - -static ZEND_COLD int zend_closure_has_property(zend_object *object, zend_string *member, int has_set_exists, void **cache_slot) /* {{{ */ -{ - if (has_set_exists != ZEND_PROPERTY_EXISTS) { - ZEND_CLOSURE_PROPERTY_ERROR(); - } - return 0; -} -/* }}} */ - -static ZEND_COLD void zend_closure_unset_property(zend_object *object, zend_string *member, void **cache_slot) /* {{{ */ -{ - ZEND_CLOSURE_PROPERTY_ERROR(); -} -/* }}} */ - static void zend_closure_free_storage(zend_object *object) /* {{{ */ { zend_closure *closure = (zend_closure *)object; @@ -645,11 +604,6 @@ void zend_register_closure_ce(void) /* {{{ */ closure_handlers.free_obj = zend_closure_free_storage; closure_handlers.get_constructor = zend_closure_get_constructor; closure_handlers.get_method = zend_closure_get_method; - closure_handlers.write_property = zend_closure_write_property; - closure_handlers.read_property = zend_closure_read_property; - closure_handlers.get_property_ptr_ptr = zend_closure_get_property_ptr_ptr; - closure_handlers.has_property = zend_closure_has_property; - closure_handlers.unset_property = zend_closure_unset_property; closure_handlers.compare = zend_closure_compare; closure_handlers.clone_obj = zend_closure_clone; closure_handlers.get_debug_info = zend_closure_get_debug_info; diff --git a/Zend/zend_closures.stub.php b/Zend/zend_closures.stub.php index 4bd93e241fa..3d451e58b69 100644 --- a/Zend/zend_closures.stub.php +++ b/Zend/zend_closures.stub.php @@ -2,6 +2,7 @@ /** @generate-class-entries */ +/** @strict-properties */ final class Closure { private function __construct() {} diff --git a/Zend/zend_closures_arginfo.h b/Zend/zend_closures_arginfo.h index 56bd16ffb65..888e4994a08 100644 --- a/Zend/zend_closures_arginfo.h +++ b/Zend/zend_closures_arginfo.h @@ -1,5 +1,5 @@ /* This is a generated file, edit the .stub.php file instead. - * Stub hash: 62da9b1e75331f30a0c63e82c9fd366e26b5724d */ + * Stub hash: 7c4df531cdb30ac4206f43f0d40098666466b9a6 */ ZEND_BEGIN_ARG_INFO_EX(arginfo_class_Closure___construct, 0, 0, 0) ZEND_END_ARG_INFO() @@ -47,7 +47,7 @@ static zend_class_entry *register_class_Closure(void) INIT_CLASS_ENTRY(ce, "Closure", class_Closure_methods); class_entry = zend_register_internal_class_ex(&ce, NULL); - class_entry->ce_flags |= ZEND_ACC_FINAL; + class_entry->ce_flags |= ZEND_ACC_FINAL|ZEND_ACC_NO_DYNAMIC_PROPERTIES; return class_entry; }