com php-src: Changed behavior of uninitialized nullable properties (accoding to conversation with Joe): Zend/tests/type_declarat
ions/typed_properties_047.phpt Zend/tests/type_ declarations/typed_properties_048.phpt Zend/zend _API.c Zend/zend_object_handlers.c

From: Date: Wed, 25 May 2016 09:29:52 +0000
Subject: com php-src: Changed behavior of uninitialized nullable properties (accoding to conversation with Joe): Zend/tests/type_declarat
ions/typed_properties_047.phpt Zend/tests/type_ declarations/typed_properties_048.phpt Zend/zend _API.c Zend/zend_object_handlers.c
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-95515@lists.php.net to get a copy of this message
Commit: f4b40515868b4329c918a1f5fa2ef8acbd8f4d21 Author: Dmitry Stogov <dmitry@zend.com> Wed, 25 May 2016 12:29:52 +0300 Parents: c992fcf593ac1c216692d3fd6853a95360d9316f Branches: typed_ref_properties Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=f4b40515868b4329c918a1f5fa2ef8acbd8f4d21 Log: Changed behavior of uninitialized nullable properties (accoding to conversation with Joe) Changed paths: M Zend/tests/type_declarations/typed_properties_047.phpt M Zend/tests/type_declarations/typed_properties_048.phpt M Zend/zend_API.c M Zend/zend_object_handlers.c Diff: diff --git a/Zend/tests/type_declarations/typed_properties_047.phpt b/Zend/tests/type_declarations/typed_properties_047.phpt index dc59276..d3bdc23 100644 --- a/Zend/tests/type_declarations/typed_properties_047.phpt +++ b/Zend/tests/type_declarations/typed_properties_047.phpt @@ -48,13 +48,15 @@ try { echo $e->getMessage()."\n"; } ?> ---EXPECT-- -object(Foo)#1 (0) { +--EXPECTF-- +object(Foo)#1 (1) { ["foo"]=> - uninitialized(?integer) + NULL } -Typed property Foo::$foo must not be accessed before initialization +NULL int(5) NULL -Typed property Foo::$foo must not be accessed before initialization + +Notice: Undefined property: Foo::$foo in %styped_properties_047.php on line 38 +NULL Typed property Foo::$foo must be integer, string used diff --git a/Zend/tests/type_declarations/typed_properties_048.phpt b/Zend/tests/type_declarations/typed_properties_048.phpt index b0a7517..0bdb0f6 100644 --- a/Zend/tests/type_declarations/typed_properties_048.phpt +++ b/Zend/tests/type_declarations/typed_properties_048.phpt @@ -48,7 +48,7 @@ try { echo $e->getMessage()."\n"; } ?> ---EXPECT-- +--EXPECTF-- object(Foo)#1 (1) { ["foo"]=> NULL @@ -56,5 +56,7 @@ object(Foo)#1 (1) { NULL int(5) NULL -Typed property Foo::$foo must not be accessed before initialization + +Notice: Undefined property: Foo::$foo in %styped_properties_048.php on line 38 +NULL Typed property Foo::$foo must be integer, string used diff --git a/Zend/zend_API.c b/Zend/zend_API.c index 885b0ff..73db276 100644 --- a/Zend/zend_API.c +++ b/Zend/zend_API.c @@ -3638,7 +3638,7 @@ ZEND_API int zend_declare_typed_property(zend_class_entry *ce, zend_string *name } } - if (Z_ISUNDEF_P(property) && !optional_type) { + if (Z_ISUNDEF_P(property) && (!optional_type || allow_null)) { ZVAL_NULL(property); } diff --git a/Zend/zend_object_handlers.c b/Zend/zend_object_handlers.c index 5daaeae..53e4199 100644 --- a/Zend/zend_object_handlers.c +++ b/Zend/zend_object_handlers.c @@ -694,7 +694,8 @@ zval *zend_std_read_property(zval *object, zval *member, int type, void **cache_ } } if ((type != BP_VAR_IS)) { - if (UNEXPECTED(prop_info = zend_object_fetch_property_type_info_ex(object, Z_STR_P(member), cache_slot))) { + if (UNEXPECTED(prop_info = zend_object_fetch_property_type_info_ex(object, Z_STR_P(member), cache_slot)) + && UNEXPECTED(!prop_info->allow_null)) { zend_throw_exception_ex(zend_ce_type_error, prop_info->type, "Typed property %s::$%s must not be accessed before initialization", ZSTR_VAL(prop_info->ce->name),

« previous php.cvs (#95515) next »