com php-src: some tests ...: Zend/tests/type_declarations/typ ed_properties_001.phpt Zend/tests/type_declarat ions/typed_properties_002.phpt
Zend/tests/type_ declarations/typed_properties_003.phpt Zend/tests /type_declarations/typed_properties_004.phpt Ze nd/zend_vm_def.h
Zend/zend_vm_execute.h

From: Date: Sun, 06 Mar 2016 18:34:15 +0000
Subject: com php-src: some tests ...: Zend/tests/type_declarations/typ ed_properties_001.phpt Zend/tests/type_declarat ions/typed_properties_002.phpt
Zend/tests/type_ declarations/typed_properties_003.phpt Zend/tests /type_declarations/typed_properties_004.phpt Ze nd/zend_vm_def.h
Zend/zend_vm_execute.h
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-95640@lists.php.net to get a copy of this message
Commit: 5a07809ff40153533cc3322e1e96df88e57223a3 Author: Joe Watkins <krakjoe@php.net> Sun, 6 Mar 2016 18:34:15 +0000 Parents: 70e0e4d7832a211da178aae3bd5513cf67aedd90 Branches: typed_ref_properties Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=5a07809ff40153533cc3322e1e96df88e57223a3 Log: some tests ... Changed paths: A Zend/tests/type_declarations/typed_properties_001.phpt A Zend/tests/type_declarations/typed_properties_002.phpt A Zend/tests/type_declarations/typed_properties_003.phpt A Zend/tests/type_declarations/typed_properties_004.phpt M Zend/zend_vm_def.h M Zend/zend_vm_execute.h

diff --git a/Zend/tests/type_declarations/typed_properties_001.phpt b/Zend/tests/type_declarations/typed_properties_001.phpt new file mode 100644 index 0000000..054fc4d --- /dev/null +++ b/Zend/tests/type_declarations/typed_properties_001.phpt @@ -0,0 +1,38 @@ +--TEST-- +Test typed properties basic operation +--FILE-- +<?php +var_dump(new class(1, 2.2, true, ["four"], new stdClass) { + public int $int; + public float $float; + public bool $bool; + public array $array; + public stdClass $std; + + public function __construct(int $int, float $float, bool $bool, array $array, stdClass $std) { + $this->int = $int; + $this->float = $float; + $this->bool = $bool; + $this->array = $array; + $this->std = $std; + } +}); +?> +--EXPECTF-- +object(class@anonymous)#%d (5) { + ["int"]=> + int(1) + ["float"]=> + float(2.2) + ["bool"]=> + bool(true) + ["array"]=> + array(1) { + [0]=> + string(4) "four" + } + ["std"]=> + object(stdClass)#%d (0) { + } +} + diff --git a/Zend/tests/type_declarations/typed_properties_002.phpt b/Zend/tests/type_declarations/typed_properties_002.phpt new file mode 100644 index 0000000..a046d79 --- /dev/null +++ b/Zend/tests/type_declarations/typed_properties_002.phpt @@ -0,0 +1,17 @@ +--TEST-- +Test typed properties error condition (read uninitialized) +--FILE-- +<?php +$thing = new class() { + public int $int; +}; + +var_dump($thing->int); +?> +--EXPECTF-- +Fatal error: Uncaught TypeError: class@anonymous::$int accessed before initialization in %s:6 +Stack trace: +#0 {main} + thrown in %s on line 6 + + diff --git a/Zend/tests/type_declarations/typed_properties_003.phpt b/Zend/tests/type_declarations/typed_properties_003.phpt new file mode 100644 index 0000000..b2743a9 --- /dev/null +++ b/Zend/tests/type_declarations/typed_properties_003.phpt @@ -0,0 +1,17 @@ +--TEST-- +Test typed properties error condition (fetch reference) +--FILE-- +<?php +$thing = new class() { + public int $int; +}; + +$var = &$thing->int; +?> +--EXPECTF-- +Fatal error: Uncaught TypeError: fetching reference to class@anonymous::$int is disallowed in %s:6 +Stack trace: +#0 {main} + thrown in %s on line 6 + + diff --git a/Zend/tests/type_declarations/typed_properties_004.phpt b/Zend/tests/type_declarations/typed_properties_004.phpt new file mode 100644 index 0000000..668b518 --- /dev/null +++ b/Zend/tests/type_declarations/typed_properties_004.phpt @@ -0,0 +1,20 @@ +--TEST-- +Test typed properties error condition (type mismatch) +--FILE-- +<?php +$thing = new class("PHP 7 is better than you, and it knows it ...") { + public int $int; + + public function __construct(string $string) { + $this->int = $string; + } +}; +?> +--EXPECTF-- +Fatal error: Uncaught TypeError: class@anonymous::$int must be integer in %s:6 +Stack trace: +#0 %s(2): class@anonymous->__construct('PHP 7 is better...') +#1 {main} + thrown in %s on line 6 + + diff --git a/Zend/zend_vm_def.h b/Zend/zend_vm_def.h index 1384248..8528008 100644 --- a/Zend/zend_vm_def.h +++ b/Zend/zend_vm_def.h @@ -1869,10 +1869,9 @@ ZEND_VM_C_LABEL(fetch_obj_r_no_object): if (prop_info && prop_info->type && Z_TYPE_P(EX_VAR(opline->result.var)) != prop_info->type) { zend_throw_exception_ex(zend_ce_type_error, prop_info->type, - "%s::$%s accessed before initialization (%s)", + "%s::$%s accessed before initialization", ZSTR_VAL(Z_OBJCE_P(container)->name), - Z_STRVAL_P(offset), - zend_get_type_by_const(prop_info->type)); + Z_STRVAL_P(offset)); HANDLE_EXCEPTION(); } } diff --git a/Zend/zend_vm_execute.h b/Zend/zend_vm_execute.h index 50892bc..6a89f40 100644 --- a/Zend/zend_vm_execute.h +++ b/Zend/zend_vm_execute.h @@ -5616,10 +5616,9 @@ fetch_obj_r_no_object: if (prop_info && prop_info->type && Z_TYPE_P(EX_VAR(opline->result.var)) != prop_info->type) { zend_throw_exception_ex(zend_ce_type_error, prop_info->type, - "%s::$%s accessed before initialization (%s)", + "%s::$%s accessed before initialization", ZSTR_VAL(Z_OBJCE_P(container)->name), - Z_STRVAL_P(offset), - zend_get_type_by_const(prop_info->type)); + Z_STRVAL_P(offset)); HANDLE_EXCEPTION(); } } @@ -9383,10 +9382,9 @@ fetch_obj_r_no_object: if (prop_info && prop_info->type && Z_TYPE_P(EX_VAR(opline->result.var)) != prop_info->type) { zend_throw_exception_ex(zend_ce_type_error, prop_info->type, - "%s::$%s accessed before initialization (%s)", + "%s::$%s accessed before initialization", ZSTR_VAL(Z_OBJCE_P(container)->name), - Z_STRVAL_P(offset), - zend_get_type_by_const(prop_info->type)); + Z_STRVAL_P(offset)); HANDLE_EXCEPTION(); } } @@ -11202,10 +11200,9 @@ fetch_obj_r_no_object: if (prop_info && prop_info->type && Z_TYPE_P(EX_VAR(opline->result.var)) != prop_info->type) { zend_throw_exception_ex(zend_ce_type_error, prop_info->type, - "%s::$%s accessed before initialization (%s)", + "%s::$%s accessed before initialization", ZSTR_VAL(Z_OBJCE_P(container)->name), - Z_STRVAL_P(offset), - zend_get_type_by_const(prop_info->type)); + Z_STRVAL_P(offset)); HANDLE_EXCEPTION(); } } @@ -13134,10 +13131,9 @@ fetch_obj_r_no_object: if (prop_info && prop_info->type && Z_TYPE_P(EX_VAR(opline->result.var)) != prop_info->type) { zend_throw_exception_ex(zend_ce_type_error, prop_info->type, - "%s::$%s accessed before initialization (%s)", + "%s::$%s accessed before initialization", ZSTR_VAL(Z_OBJCE_P(container)->name), - Z_STRVAL_P(offset), - zend_get_type_by_const(prop_info->type)); + Z_STRVAL_P(offset)); HANDLE_EXCEPTION(); } } @@ -14377,10 +14373,9 @@ fetch_obj_r_no_object: if (prop_info && prop_info->type && Z_TYPE_P(EX_VAR(opline->result.var)) != prop_info->type) { zend_throw_exception_ex(zend_ce_type_error, prop_info->type, - "%s::$%s accessed before initialization (%s)", + "%s::$%s accessed before initialization", ZSTR_VAL(Z_OBJCE_P(container)->name), - Z_STRVAL_P(offset), - zend_get_type_by_const(prop_info->type)); + Z_STRVAL_P(offset)); HANDLE_EXCEPTION(); } } @@ -14921,10 +14916,9 @@ fetch_obj_r_no_object: if (prop_info && prop_info->type && Z_TYPE_P(EX_VAR(opline->result.var)) != prop_info->type) { zend_throw_exception_ex(zend_ce_type_error, prop_info->type, - "%s::$%s accessed before initialization (%s)", + "%s::$%s accessed before initialization", ZSTR_VAL(Z_OBJCE_P(container)->name), - Z_STRVAL_P(offset), - zend_get_type_by_const(prop_info->type)); + Z_STRVAL_P(offset)); HANDLE_EXCEPTION(); } } @@ -17627,10 +17621,9 @@ fetch_obj_r_no_object: if (prop_info && prop_info->type && Z_TYPE_P(EX_VAR(opline->result.var)) != prop_info->type) { zend_throw_exception_ex(zend_ce_type_error, prop_info->type, - "%s::$%s accessed before initialization (%s)", + "%s::$%s accessed before initialization", ZSTR_VAL(Z_OBJCE_P(container)->name), - Z_STRVAL_P(offset), - zend_get_type_by_const(prop_info->type)); + Z_STRVAL_P(offset)); HANDLE_EXCEPTION(); } } @@ -22171,10 +22164,9 @@ fetch_obj_r_no_object: if (prop_info && prop_info->type && Z_TYPE_P(EX_VAR(opline->result.var)) != prop_info->type) { zend_throw_exception_ex(zend_ce_type_error, prop_info->type, - "%s::$%s accessed before initialization (%s)", + "%s::$%s accessed before initialization", ZSTR_VAL(Z_OBJCE_P(container)->name), - Z_STRVAL_P(offset), - zend_get_type_by_const(prop_info->type)); + Z_STRVAL_P(offset)); HANDLE_EXCEPTION(); } } @@ -24910,10 +24902,9 @@ fetch_obj_r_no_object: if (prop_info && prop_info->type && Z_TYPE_P(EX_VAR(opline->result.var)) != prop_info->type) { zend_throw_exception_ex(zend_ce_type_error, prop_info->type, - "%s::$%s accessed before initialization (%s)", + "%s::$%s accessed before initialization", ZSTR_VAL(Z_OBJCE_P(container)->name), - Z_STRVAL_P(offset), - zend_get_type_by_const(prop_info->type)); + Z_STRVAL_P(offset)); HANDLE_EXCEPTION(); } } @@ -27434,10 +27425,9 @@ fetch_obj_r_no_object: if (prop_info && prop_info->type && Z_TYPE_P(EX_VAR(opline->result.var)) != prop_info->type) { zend_throw_exception_ex(zend_ce_type_error, prop_info->type, - "%s::$%s accessed before initialization (%s)", + "%s::$%s accessed before initialization", ZSTR_VAL(Z_OBJCE_P(container)->name), - Z_STRVAL_P(offset), - zend_get_type_by_const(prop_info->type)); + Z_STRVAL_P(offset)); HANDLE_EXCEPTION(); } } @@ -30926,10 +30916,9 @@ fetch_obj_r_no_object: if (prop_info && prop_info->type && Z_TYPE_P(EX_VAR(opline->result.var)) != prop_info->type) { zend_throw_exception_ex(zend_ce_type_error, prop_info->type, - "%s::$%s accessed before initialization (%s)", + "%s::$%s accessed before initialization", ZSTR_VAL(Z_OBJCE_P(container)->name), - Z_STRVAL_P(offset), - zend_get_type_by_const(prop_info->type)); + Z_STRVAL_P(offset)); HANDLE_EXCEPTION(); } } @@ -33360,10 +33349,9 @@ fetch_obj_r_no_object: if (prop_info && prop_info->type && Z_TYPE_P(EX_VAR(opline->result.var)) != prop_info->type) { zend_throw_exception_ex(zend_ce_type_error, prop_info->type, - "%s::$%s accessed before initialization (%s)", + "%s::$%s accessed before initialization", ZSTR_VAL(Z_OBJCE_P(container)->name), - Z_STRVAL_P(offset), - zend_get_type_by_const(prop_info->type)); + Z_STRVAL_P(offset)); HANDLE_EXCEPTION(); } } @@ -38372,10 +38360,9 @@ fetch_obj_r_no_object: if (prop_info && prop_info->type && Z_TYPE_P(EX_VAR(opline->result.var)) != prop_info->type) { zend_throw_exception_ex(zend_ce_type_error, prop_info->type, - "%s::$%s accessed before initialization (%s)", + "%s::$%s accessed before initialization", ZSTR_VAL(Z_OBJCE_P(container)->name), - Z_STRVAL_P(offset), - zend_get_type_by_const(prop_info->type)); + Z_STRVAL_P(offset)); HANDLE_EXCEPTION(); } } @@ -44927,10 +44914,9 @@ fetch_obj_r_no_object: if (prop_info && prop_info->type && Z_TYPE_P(EX_VAR(opline->result.var)) != prop_info->type) { zend_throw_exception_ex(zend_ce_type_error, prop_info->type, - "%s::$%s accessed before initialization (%s)", + "%s::$%s accessed before initialization", ZSTR_VAL(Z_OBJCE_P(container)->name), - Z_STRVAL_P(offset), - zend_get_type_by_const(prop_info->type)); + Z_STRVAL_P(offset)); HANDLE_EXCEPTION(); } } @@ -48652,10 +48638,9 @@ fetch_obj_r_no_object: if (prop_info && prop_info->type && Z_TYPE_P(EX_VAR(opline->result.var)) != prop_info->type) { zend_throw_exception_ex(zend_ce_type_error, prop_info->type, - "%s::$%s accessed before initialization (%s)", + "%s::$%s accessed before initialization", ZSTR_VAL(Z_OBJCE_P(container)->name), - Z_STRVAL_P(offset), - zend_get_type_by_const(prop_info->type)); + Z_STRVAL_P(offset)); HANDLE_EXCEPTION(); } }
« previous php.cvs (#95640) next »