summaryrefslogtreecommitdiff
path: root/ext/standard/tests
diff options
context:
space:
mode:
authorNikita Popov <nikita.ppv@gmail.com>2020-01-06 18:47:44 +0100
committerNikita Popov <nikita.ppv@gmail.com>2020-01-06 18:47:44 +0100
commitb22daa3a06fcb033b51cf694da7cb20f78bbe2a6 (patch)
treebe2a203dc57d25e69548ac0741d45eab0cabb09c /ext/standard/tests
parentd9caf3561b856336bdf8d20c174e29d7a92a2345 (diff)
parent846b6479537a112d1ded725e6484e46462048b35 (diff)
downloadphp-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.phpt60
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)
+}