diff options
author | Nikita Popov <nikita.ppv@gmail.com> | 2019-01-07 12:28:51 +0100 |
---|---|---|
committer | Nikita Popov <nikita.ppv@gmail.com> | 2019-01-11 15:49:06 +0100 |
commit | e219ec144ef6682b71e135fd18654ee1bb4676b4 (patch) | |
tree | e4a3ae2b619cdc9fe50ee8e1fa5adb99d804dddf /Zend/tests/type_declarations/typed_properties_034.phpt | |
parent | fe8fdfa3bd588d80ce60f6b3848058239e0a760f (diff) | |
download | php-git-e219ec144ef6682b71e135fd18654ee1bb4676b4.tar.gz |
Implement typed properties
RFC: https://wiki.php.net/rfc/typed_properties_v2
This is a squash of PR #3734, which is a squash of PR #3313.
Co-authored-by: Bob Weinand <bobwei9@hotmail.com>
Co-authored-by: Joe Watkins <krakjoe@php.net>
Co-authored-by: Dmitry Stogov <dmitry@zend.com>
Diffstat (limited to 'Zend/tests/type_declarations/typed_properties_034.phpt')
-rw-r--r-- | Zend/tests/type_declarations/typed_properties_034.phpt | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/Zend/tests/type_declarations/typed_properties_034.phpt b/Zend/tests/type_declarations/typed_properties_034.phpt new file mode 100644 index 0000000000..c3885af39f --- /dev/null +++ b/Zend/tests/type_declarations/typed_properties_034.phpt @@ -0,0 +1,51 @@ +--TEST-- +Test typed properties passed to typed function +--FILE-- +<?php +$foo = new class { + public ?int $bar = 42; + public int $baz; + + public function &getIterator() { + foreach (['1', &$this->bar] as &$item) { + yield $item; + } + } +}; + +function foo(?int &$a) { + var_dump($a); + $a = null; +} + +foo($foo->bar); + +try { + $foo->baz = &$foo->bar; +} catch (Error $e) { echo $e->getMessage(), "\n"; } +$foo->bar = 10; + +foreach ($foo->getIterator() as &$item) { + $foo->baz = &$item; + var_dump($foo->baz); +} + +try { + foo($foo->bar); +} catch (Error $e) { echo $e->getMessage(), "\n"; } + +var_dump($foo); +?> +--EXPECT-- +int(42) +Typed property class@anonymous::$baz must be int, null used +int(1) +int(10) +int(10) +Cannot assign null to reference held by property class@anonymous::$baz of type int +object(class@anonymous)#1 (2) { + ["bar"]=> + &int(10) + ["baz"]=> + &int(10) +} |