com php-src: test widening, fix uninitialized access check: Zend/tests/type_declarations/typed_properties_019 .phpt Zend/zend_vm_def.h
Zend/zend_vm_execute .h

From: Date: Wed, 09 Mar 2016 06:12:38 +0000
Subject: com php-src: test widening, fix uninitialized access check: Zend/tests/type_declarations/typed_properties_019 .phpt Zend/zend_vm_def.h
Zend/zend_vm_execute .h
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-95594@lists.php.net to get a copy of this message
Commit: 90e18dbad4193905211dbd2640b11e369e956250 Author: Joe Watkins <krakjoe@php.net> Wed, 9 Mar 2016 06:12:38 +0000 Parents: b4ec5eb9f23899c20cc88262570d3cbfd4dc5c8c Branches: typed_ref_properties Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=90e18dbad4193905211dbd2640b11e369e956250 Log: test widening, fix uninitialized access check Changed paths: A Zend/tests/type_declarations/typed_properties_019.phpt M Zend/zend_vm_def.h M Zend/zend_vm_execute.h

diff --git a/Zend/tests/type_declarations/typed_properties_019.phpt b/Zend/tests/type_declarations/typed_properties_019.phpt new file mode 100644 index 0000000..906ea1c --- /dev/null +++ b/Zend/tests/type_declarations/typed_properties_019.phpt @@ -0,0 +1,21 @@ +--TEST-- +Test typed int must be allowed to widen to float +--FILE-- +<?php +class Foo { + + public int $bar = 1; +} + +$foo = new Foo(); +$foo->bar = 2.2; + +var_dump($foo->bar); +?> +--EXPECT-- +float(2.2) + + + + + diff --git a/Zend/zend_vm_def.h b/Zend/zend_vm_def.h index d74f84a..aff7c2c 100644 --- a/Zend/zend_vm_def.h +++ b/Zend/zend_vm_def.h @@ -1865,7 +1865,7 @@ ZEND_VM_C_LABEL(fetch_obj_r_no_object): zend_property_info *prop_info = zend_hash_find_ptr(&Z_OBJCE_P(container)->properties_info, Z_STR_P(offset)); if (prop_info && prop_info->type && - Z_TYPE_P(EX_VAR(opline->result.var)) != prop_info->type) { + Z_TYPE_P(EX_VAR(opline->result.var)) == 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(Z_OBJCE_P(container)->name), diff --git a/Zend/zend_vm_execute.h b/Zend/zend_vm_execute.h index 081c009..8eb6672 100644 --- a/Zend/zend_vm_execute.h +++ b/Zend/zend_vm_execute.h @@ -4263,7 +4263,7 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_FE_RESET_RW_SPEC_CONST_HANDLER ZEND_VM_NEXT_OPCODE_CHECK_EXCEPTION(); } else if (IS_CONST != IS_CONST && EXPECTED(Z_TYPE_P(array_ptr) == IS_OBJECT)) { - if (Z_OBJCE_P(array_ptr)->ce_flags & ZEND_ACC_HAS_TYPE_HINTS) { + if (UNEXPECTED(Z_OBJCE_P(array_ptr)->ce_flags & ZEND_ACC_HAS_TYPE_HINTS)) { zend_throw_exception_ex( zend_ce_type_error, 0, "Typed properties exist in %s: foreach by reference is disallowed", @@ -5620,7 +5620,7 @@ fetch_obj_r_no_object: zend_property_info *prop_info = zend_hash_find_ptr(&Z_OBJCE_P(container)->properties_info, Z_STR_P(offset)); if (prop_info && prop_info->type && - Z_TYPE_P(EX_VAR(opline->result.var)) != prop_info->type) { + Z_TYPE_P(EX_VAR(opline->result.var)) == 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(Z_OBJCE_P(container)->name), @@ -9401,7 +9401,7 @@ fetch_obj_r_no_object: zend_property_info *prop_info = zend_hash_find_ptr(&Z_OBJCE_P(container)->properties_info, Z_STR_P(offset)); if (prop_info && prop_info->type && - Z_TYPE_P(EX_VAR(opline->result.var)) != prop_info->type) { + Z_TYPE_P(EX_VAR(opline->result.var)) == 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(Z_OBJCE_P(container)->name), @@ -11234,7 +11234,7 @@ fetch_obj_r_no_object: zend_property_info *prop_info = zend_hash_find_ptr(&Z_OBJCE_P(container)->properties_info, Z_STR_P(offset)); if (prop_info && prop_info->type && - Z_TYPE_P(EX_VAR(opline->result.var)) != prop_info->type) { + Z_TYPE_P(EX_VAR(opline->result.var)) == 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(Z_OBJCE_P(container)->name), @@ -12677,7 +12677,7 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_FE_RESET_RW_SPEC_TMP_HANDLER(Z ZEND_VM_NEXT_OPCODE_CHECK_EXCEPTION(); } else if (IS_TMP_VAR != IS_CONST && EXPECTED(Z_TYPE_P(array_ptr) == IS_OBJECT)) { - if (Z_OBJCE_P(array_ptr)->ce_flags & ZEND_ACC_HAS_TYPE_HINTS) { + if (UNEXPECTED(Z_OBJCE_P(array_ptr)->ce_flags & ZEND_ACC_HAS_TYPE_HINTS)) { zend_throw_exception_ex( zend_ce_type_error, 0, "Typed properties exist in %s: foreach by reference is disallowed", @@ -13188,7 +13188,7 @@ fetch_obj_r_no_object: zend_property_info *prop_info = zend_hash_find_ptr(&Z_OBJCE_P(container)->properties_info, Z_STR_P(offset)); if (prop_info && prop_info->type && - Z_TYPE_P(EX_VAR(opline->result.var)) != prop_info->type) { + Z_TYPE_P(EX_VAR(opline->result.var)) == 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(Z_OBJCE_P(container)->name), @@ -14445,7 +14445,7 @@ fetch_obj_r_no_object: zend_property_info *prop_info = zend_hash_find_ptr(&Z_OBJCE_P(container)->properties_info, Z_STR_P(offset)); if (prop_info && prop_info->type && - Z_TYPE_P(EX_VAR(opline->result.var)) != prop_info->type) { + Z_TYPE_P(EX_VAR(opline->result.var)) == 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(Z_OBJCE_P(container)->name), @@ -15003,7 +15003,7 @@ fetch_obj_r_no_object: zend_property_info *prop_info = zend_hash_find_ptr(&Z_OBJCE_P(container)->properties_info, Z_STR_P(offset)); if (prop_info && prop_info->type && - Z_TYPE_P(EX_VAR(opline->result.var)) != prop_info->type) { + Z_TYPE_P(EX_VAR(opline->result.var)) == 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(Z_OBJCE_P(container)->name), @@ -16275,7 +16275,7 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_FE_RESET_RW_SPEC_VAR_HANDLER(Z if (UNEXPECTED(free_op1)) {zval_ptr_dtor_nogc(free_op1);}; ZEND_VM_NEXT_OPCODE_CHECK_EXCEPTION(); } else if (IS_VAR != IS_CONST && EXPECTED(Z_TYPE_P(array_ptr) == IS_OBJECT)) { - if (Z_OBJCE_P(array_ptr)->ce_flags & ZEND_ACC_HAS_TYPE_HINTS) { + if (UNEXPECTED(Z_OBJCE_P(array_ptr)->ce_flags & ZEND_ACC_HAS_TYPE_HINTS)) { zend_throw_exception_ex( zend_ce_type_error, 0, "Typed properties exist in %s: foreach by reference is disallowed", @@ -17731,7 +17731,7 @@ fetch_obj_r_no_object: zend_property_info *prop_info = zend_hash_find_ptr(&Z_OBJCE_P(container)->properties_info, Z_STR_P(offset)); if (prop_info && prop_info->type && - Z_TYPE_P(EX_VAR(opline->result.var)) != prop_info->type) { + Z_TYPE_P(EX_VAR(opline->result.var)) == 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(Z_OBJCE_P(container)->name), @@ -22217,7 +22217,7 @@ fetch_obj_r_no_object: zend_property_info *prop_info = zend_hash_find_ptr(&Z_OBJCE_P(container)->properties_info, Z_STR_P(offset)); if (prop_info && prop_info->type && - Z_TYPE_P(EX_VAR(opline->result.var)) != prop_info->type) { + Z_TYPE_P(EX_VAR(opline->result.var)) == 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(Z_OBJCE_P(container)->name), @@ -24898,7 +24898,7 @@ fetch_obj_r_no_object: zend_property_info *prop_info = zend_hash_find_ptr(&Z_OBJCE_P(container)->properties_info, Z_STR_P(offset)); if (prop_info && prop_info->type && - Z_TYPE_P(EX_VAR(opline->result.var)) != prop_info->type) { + Z_TYPE_P(EX_VAR(opline->result.var)) == 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(Z_OBJCE_P(container)->name), @@ -27364,7 +27364,7 @@ fetch_obj_r_no_object: zend_property_info *prop_info = zend_hash_find_ptr(&Z_OBJCE_P(container)->properties_info, Z_STR_P(offset)); if (prop_info && prop_info->type && - Z_TYPE_P(EX_VAR(opline->result.var)) != prop_info->type) { + Z_TYPE_P(EX_VAR(opline->result.var)) == 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(Z_OBJCE_P(container)->name), @@ -30798,7 +30798,7 @@ fetch_obj_r_no_object: zend_property_info *prop_info = zend_hash_find_ptr(&Z_OBJCE_P(container)->properties_info, Z_STR_P(offset)); if (prop_info && prop_info->type && - Z_TYPE_P(EX_VAR(opline->result.var)) != prop_info->type) { + Z_TYPE_P(EX_VAR(opline->result.var)) == 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(Z_OBJCE_P(container)->name), @@ -33174,7 +33174,7 @@ fetch_obj_r_no_object: zend_property_info *prop_info = zend_hash_find_ptr(&Z_OBJCE_P(container)->properties_info, Z_STR_P(offset)); if (prop_info && prop_info->type && - Z_TYPE_P(EX_VAR(opline->result.var)) != prop_info->type) { + Z_TYPE_P(EX_VAR(opline->result.var)) == 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(Z_OBJCE_P(container)->name), @@ -36216,7 +36216,7 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_FE_RESET_RW_SPEC_CV_HANDLER(ZE ZEND_VM_NEXT_OPCODE_CHECK_EXCEPTION(); } else if (IS_CV != IS_CONST && EXPECTED(Z_TYPE_P(array_ptr) == IS_OBJECT)) { - if (Z_OBJCE_P(array_ptr)->ce_flags & ZEND_ACC_HAS_TYPE_HINTS) { + if (UNEXPECTED(Z_OBJCE_P(array_ptr)->ce_flags & ZEND_ACC_HAS_TYPE_HINTS)) { zend_throw_exception_ex( zend_ce_type_error, 0, "Typed properties exist in %s: foreach by reference is disallowed", @@ -38136,7 +38136,7 @@ fetch_obj_r_no_object: zend_property_info *prop_info = zend_hash_find_ptr(&Z_OBJCE_P(container)->properties_info, Z_STR_P(offset)); if (prop_info && prop_info->type && - Z_TYPE_P(EX_VAR(opline->result.var)) != prop_info->type) { + Z_TYPE_P(EX_VAR(opline->result.var)) == 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(Z_OBJCE_P(container)->name), @@ -44633,7 +44633,7 @@ fetch_obj_r_no_object: zend_property_info *prop_info = zend_hash_find_ptr(&Z_OBJCE_P(container)->properties_info, Z_STR_P(offset)); if (prop_info && prop_info->type && - Z_TYPE_P(EX_VAR(opline->result.var)) != prop_info->type) { + Z_TYPE_P(EX_VAR(opline->result.var)) == 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(Z_OBJCE_P(container)->name), @@ -48300,7 +48300,7 @@ fetch_obj_r_no_object: zend_property_info *prop_info = zend_hash_find_ptr(&Z_OBJCE_P(container)->properties_info, Z_STR_P(offset)); if (prop_info && prop_info->type && - Z_TYPE_P(EX_VAR(opline->result.var)) != prop_info->type) { + Z_TYPE_P(EX_VAR(opline->result.var)) == 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(Z_OBJCE_P(container)->name),
« previous php.cvs (#95594) next »