diff options
author | Nikita Popov <nikita.ppv@gmail.com> | 2020-01-06 18:47:44 +0100 |
---|---|---|
committer | Nikita Popov <nikita.ppv@gmail.com> | 2020-01-06 18:47:44 +0100 |
commit | b22daa3a06fcb033b51cf694da7cb20f78bbe2a6 (patch) | |
tree | be2a203dc57d25e69548ac0741d45eab0cabb09c /ext/standard/tests | |
parent | d9caf3561b856336bdf8d20c174e29d7a92a2345 (diff) | |
parent | 846b6479537a112d1ded725e6484e46462048b35 (diff) | |
download | php-git-b22daa3a06fcb033b51cf694da7cb20f78bbe2a6.tar.gz |
Merge branch 'PHP-7.4'
* PHP-7.4:
Throw Error when referencing uninit typed prop in __sleep
Diffstat (limited to 'ext/standard/tests')
-rw-r--r-- | ext/standard/tests/serialize/sleep_uninitialized_typed_prop.phpt | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/ext/standard/tests/serialize/sleep_uninitialized_typed_prop.phpt b/ext/standard/tests/serialize/sleep_uninitialized_typed_prop.phpt new file mode 100644 index 0000000000..3d78e11f28 --- /dev/null +++ b/ext/standard/tests/serialize/sleep_uninitialized_typed_prop.phpt @@ -0,0 +1,60 @@ +--TEST-- +Referencing an uninitialized typed property in __sleep() should result in Error +--FILE-- +<?php + +class Test { + public int $x; + protected int $y; + private int $z; + + public function __sleep() { + return ['x', 'y', 'z']; + } + + public function __set($name, $val) { + $this->$name = $val; + } +} + +$t = new Test; +try { + serialize($t); +} catch (Error $e) { + echo $e->getMessage(), "\n"; +} + +$t->x = 1; +try { + serialize($t); +} catch (Error $e) { + echo $e->getMessage(), "\n"; +} + +$t->y = 2; +try { + serialize($t); +} catch (Error $e) { + echo $e->getMessage(), "\n"; +} + +$t->z = 3; +try { + var_dump(unserialize(serialize($t))); +} catch (Error $e) { + echo $e->getMessage(), "\n"; +} + +?> +--EXPECT-- +Typed property Test::$x must not be accessed before initialization (in __sleep) +Typed property Test::$y must not be accessed before initialization (in __sleep) +Typed property Test::$z must not be accessed before initialization (in __sleep) +object(Test)#3 (3) { + ["x"]=> + int(1) + ["y":protected]=> + int(2) + ["z":"Test":private]=> + int(3) +} |