com php-src: some more improvements ... haaaands: Zend/tests/ty pe_declarations/typed_properties_020.phpt Zend/ zend_execute.c

From: Date: Wed, 06 Apr 2016 22:02:21 +0000
Subject: com php-src: some more improvements ... haaaands: Zend/tests/ty pe_declarations/typed_properties_020.phpt Zend/ zend_execute.c
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-95566@lists.php.net to get a copy of this message
Commit: 48d5aec17993e92163fce239c7a210fb0f5c6623 Author: Joe Watkins <krakjoe@php.net> Wed, 6 Apr 2016 23:02:21 +0100 Parents: e62942a2881402a846bd54f7f527b41a36fad154 Branches: typed_ref_properties Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=48d5aec17993e92163fce239c7a210fb0f5c6623 Log: some more improvements ... haaaands Changed paths: M Zend/tests/type_declarations/typed_properties_020.phpt M Zend/zend_execute.c Diff: diff --git a/Zend/tests/type_declarations/typed_properties_020.phpt b/Zend/tests/type_declarations/typed_properties_020.phpt index 95d4d5b..03fdd71 100644 --- a/Zend/tests/type_declarations/typed_properties_020.phpt +++ b/Zend/tests/type_declarations/typed_properties_020.phpt @@ -2,24 +2,20 @@ Test typed properties binary assign op helper test --FILE-- <?php -declare(strict_types=1); - class Foo { - public string $bar; + public int $bar = 0; public function __construct() { - $this->bar += 1; + $this->bar += 2; } } $foo = new Foo(); + +var_dump($foo->bar); ?> ---EXPECTF-- -Fatal error: Uncaught TypeError: Typed property Foo::$bar must be string, integer used in %s:8 -Stack trace: -#0 %s(12): Foo->__construct() -#1 {main} - thrown in %s on line 8 +--EXPECT-- +int(2) diff --git a/Zend/zend_execute.c b/Zend/zend_execute.c index f0685c0..b648ea3 100644 --- a/Zend/zend_execute.c +++ b/Zend/zend_execute.c @@ -1469,6 +1469,15 @@ static zend_never_inline void zend_pre_incdec_overloaded_property(zval *object, (prop_info = zend_object_fetch_property_type_info_ex(object, Z_STR_P(property), cache_slot)))) { zval tmp; + if (Z_TYPE_P(z) == IS_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), + Z_STRVAL_P(property)); + OBJ_RELEASE(Z_OBJ(obj)); + return; + } + ZVAL_DUP(&tmp, z); if (inc) { @@ -1541,12 +1550,21 @@ static zend_never_inline void zend_assign_op_overloaded_property(zval *object, z ZVAL_DEREF(z); SEPARATE_ZVAL_NOREF(z); - if (UNEXPECTED(ZEND_CLASS_HAS_TYPE_HINTS(Z_OBJCE(obj)) && Z_TYPE_P(property) == IS_STRING)) { + if (UNEXPECTED(ZEND_CLASS_HAS_TYPE_HINTS(Z_OBJCE(obj)) && Z_TYPE_P(property) == IS_STRING)) { zend_property_info *prop_info = zend_object_fetch_property_type_info_ex(object, Z_STR_P(property), cache_slot); if (prop_info) { zval tmp; - + + if (Z_TYPE_P(z) == IS_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), + Z_STRVAL_P(property)); + OBJ_RELEASE(Z_OBJ(obj)); + return; + } + binary_op(&tmp, z, value); if (!zend_verify_property_type(prop_info, &tmp, ZEND_CALL_USES_STRICT_TYPES(EG(current_execute_data)))) { zend_verify_property_type_error(prop_info, Z_STR_P(property), &tmp);

« previous php.cvs (#95566) next »