summaryrefslogtreecommitdiff
path: root/ext/standard/tests/general_functions/settype_typed_property.phpt
diff options
context:
space:
mode:
authorNikita Popov <nikita.ppv@gmail.com>2019-01-07 12:28:51 +0100
committerNikita Popov <nikita.ppv@gmail.com>2019-01-11 15:49:06 +0100
commite219ec144ef6682b71e135fd18654ee1bb4676b4 (patch)
treee4a3ae2b619cdc9fe50ee8e1fa5adb99d804dddf /ext/standard/tests/general_functions/settype_typed_property.phpt
parentfe8fdfa3bd588d80ce60f6b3848058239e0a760f (diff)
downloadphp-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 'ext/standard/tests/general_functions/settype_typed_property.phpt')
-rw-r--r--ext/standard/tests/general_functions/settype_typed_property.phpt28
1 files changed, 28 insertions, 0 deletions
diff --git a/ext/standard/tests/general_functions/settype_typed_property.phpt b/ext/standard/tests/general_functions/settype_typed_property.phpt
new file mode 100644
index 0000000000..a206a4ba41
--- /dev/null
+++ b/ext/standard/tests/general_functions/settype_typed_property.phpt
@@ -0,0 +1,28 @@
+--TEST--
+Using settype() on a typed property
+--FILE--
+<?php
+
+class Test {
+ public int $x;
+}
+
+$test = new Test;
+$test->x = 42;
+settype($test->x, 'string');
+// Same as $test->x = (string) $test->x.
+// Leaves value unchanged due to coercion
+var_dump($test->x);
+
+try {
+ settype($test->x, 'array');
+} catch (TypeError $e) {
+ echo $e->getMessage(), "\n";
+}
+var_dump($test->x);
+
+?>
+--EXPECT--
+int(42)
+Cannot assign array to reference held by property Test::$x of type int
+int(42)