summaryrefslogtreecommitdiff
path: root/ext/standard/tests/serialize/typed_property_refs.phpt
diff options
context:
space:
mode:
Diffstat (limited to 'ext/standard/tests/serialize/typed_property_refs.phpt')
-rw-r--r--ext/standard/tests/serialize/typed_property_refs.phpt73
1 files changed, 73 insertions, 0 deletions
diff --git a/ext/standard/tests/serialize/typed_property_refs.phpt b/ext/standard/tests/serialize/typed_property_refs.phpt
new file mode 100644
index 0000000000..9475e8a783
--- /dev/null
+++ b/ext/standard/tests/serialize/typed_property_refs.phpt
@@ -0,0 +1,73 @@
+--TEST--
+unserialize with references to typed properties shall skip the references or fail
+--FILE--
+<?php
+
+class A {
+ public int $a;
+ public $b;
+}
+
+class B {
+ public $a;
+ public int $b;
+}
+
+class C {
+ public int $a;
+ public string $b;
+}
+
+class D {
+ public int $a;
+ public float $b;
+}
+
+var_dump(unserialize('O:1:"A":2:{s:1:"a";i:1;s:1:"b";R:2;}'));
+var_dump(unserialize('O:1:"B":2:{s:1:"a";i:1;s:1:"b";R:2;}'));
+
+try {
+ var_dump(unserialize('O:1:"A":2:{s:1:"a";N;s:1:"b";R:2;}'));
+} catch (TypeError $e) {
+ echo $e->getMessage(), "\n";
+}
+try {
+ var_dump(unserialize('O:1:"B":2:{s:1:"a";N;s:1:"b";R:2;}'));
+} catch (TypeError $e) {
+ echo $e->getMessage(), "\n";
+}
+try {
+ var_dump(unserialize('O:1:"C":2:{s:1:"a";i:1;s:1:"b";R:2;}'));
+} catch (TypeError $e) {
+ echo $e->getMessage(), "\n";
+}
+try {
+ var_dump(unserialize('O:1:"C":2:{s:1:"b";s:1:"x";s:1:"a";R:2;}'));
+} catch (TypeError $e) {
+ echo $e->getMessage(), "\n";
+}
+try {
+ var_dump(unserialize('O:1:"D":2:{s:1:"a";i:1;s:1:"b";R:2;}'));
+} catch (TypeError $e) {
+ echo $e->getMessage(), "\n";
+}
+
+?>
+--EXPECT--
+object(A)#1 (2) {
+ ["a"]=>
+ &int(1)
+ ["b"]=>
+ &int(1)
+}
+object(B)#1 (2) {
+ ["a"]=>
+ &int(1)
+ ["b"]=>
+ &int(1)
+}
+Typed property A::$a must be int, null used
+Typed property B::$b must be int, null used
+Typed property C::$b must be string, int used
+Typed property C::$a must be int, string used
+Reference with value of type int held by property D::$a of type int is not compatible with property D::$b of type float