com php-src: more tests, check initial value types: Zend/tests/type_declarations/typed_properties_013 .phpt
Zend/tests/type_declarations/typed_properties_ 014.phpt Zend/tests/type_declarations/typed_prope rties_015.phpt Zend/tests/type_declarations/typed
_properties_016.phpt Zend/zend_API.c
| From: | Bob Weinand | Date: | Mon, 07 Mar 2016 14:27:29 +0000 |
| Subject: | com php-src: more tests, check initial value types: Zend/tests/type_declarations/typed_properties_013 .phpt Zend/tests/type_declarations/typed_properties_ 014.phpt Zend/tests/type_declarations/typed_prope rties_015.phpt Zend/tests/type_declarations/typed _properties_016.phpt Zend/zend_API.c |
||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-95615@lists.php.net to get a copy of this message | ||
Commit: c156399618a0137aec1e2049e62ac9fe8e0962fc
Author: Joe Watkins <krakjoe@php.net> Mon, 7 Mar 2016 14:27:29 +0000
Parents: c957e752fd76df95a0002d11dbf1073ebbebfa96
Branches: typed_ref_properties
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=c156399618a0137aec1e2049e62ac9fe8e0962fc
Log:
more tests, check initial value types
Changed paths:
A Zend/tests/type_declarations/typed_properties_013.phpt
A Zend/tests/type_declarations/typed_properties_014.phpt
A Zend/tests/type_declarations/typed_properties_015.phpt
A Zend/tests/type_declarations/typed_properties_016.phpt
M Zend/zend_API.c
Diff:
diff --git a/Zend/tests/type_declarations/typed_properties_013.phpt
b/Zend/tests/type_declarations/typed_properties_013.phpt
new file mode 100644
index 0000000..1bf8a62
--- /dev/null
+++ b/Zend/tests/type_declarations/typed_properties_013.phpt
@@ -0,0 +1,13 @@
+--TEST--
+Test typed disallow incorrect type initial value (scalar)
+--FILE--
+<?php
+class Foo {
+ public int $bar = 2.2;
+}
+?>
+--EXPECTF--
+Fatal error: Type of Foo::$bar must be integer, float used in %s on line 3
+
+
+
diff --git a/Zend/tests/type_declarations/typed_properties_014.phpt
b/Zend/tests/type_declarations/typed_properties_014.phpt
new file mode 100644
index 0000000..c9fb163
--- /dev/null
+++ b/Zend/tests/type_declarations/typed_properties_014.phpt
@@ -0,0 +1,13 @@
+--TEST--
+Test typed disallow incorrect type initial value (array)
+--FILE--
+<?php
+class Foo {
+ public array $bar = null;
+}
+?>
+--EXPECTF--
+Fatal error: Type of Foo::$bar must be array, null used in %s on line 3
+
+
+
diff --git a/Zend/tests/type_declarations/typed_properties_015.phpt
b/Zend/tests/type_declarations/typed_properties_015.phpt
new file mode 100644
index 0000000..3a1fb8f
--- /dev/null
+++ b/Zend/tests/type_declarations/typed_properties_015.phpt
@@ -0,0 +1,13 @@
+--TEST--
+Test typed disallow incorrect type initial value (object)
+--FILE--
+<?php
+class Foo {
+ public stdClass $bar = null;
+}
+?>
+--EXPECTF--
+Fatal error: Type of Foo::$bar must be stdClass, null used in %s on line 3
+
+
+
diff --git a/Zend/tests/type_declarations/typed_properties_016.phpt
b/Zend/tests/type_declarations/typed_properties_016.phpt
new file mode 100644
index 0000000..5938af1
--- /dev/null
+++ b/Zend/tests/type_declarations/typed_properties_016.phpt
@@ -0,0 +1,17 @@
+--TEST--
+Test typed initial values
+--FILE--
+<?php
+class Foo {
+ public int $int = 1;
+ public float $flt = 2..2;
+ public array $arr = [];
+ public bool $bool = false;
+}
+echo "ok\n";
+?>
+--EXPECT--
+ok
+
+
+
diff --git a/Zend/zend_API.c b/Zend/zend_API.c
index f70b1a7..66d9cab 100644
--- a/Zend/zend_API.c
+++ b/Zend/zend_API.c
@@ -3630,7 +3630,7 @@ ZEND_API int zend_declare_typed_property(zend_class_entry *ce, zend_string
*name
if (zend_string_equals_literal_ci(type_name, "parent")) {
if (!ce->parent) {
- zend_throw_exception_ex(zend_ce_type_error, optional_type,
+ zend_error(E_COMPILE_ERROR,
"Type of %s::$%s cannot be parent type, no parent scope active",
ZSTR_VAL(ce->name),
ZSTR_VAL(name));
@@ -3644,18 +3644,18 @@ ZEND_API int zend_declare_typed_property(zend_class_entry *ce, zend_string
*name
type_name = ce->name;
}
- zend_throw_exception_ex(zend_ce_type_error, optional_type,
- "Type of %s::$%s must be an instance of %s, %s used",
+ zend_error(E_COMPILE_ERROR,
+ "Type of %s::$%s must be %s, %s used",
ZSTR_VAL(ce->name),
ZSTR_VAL(name),
ZSTR_VAL(type_name),
Z_TYPE_P(property) == IS_OBJECT ?
ZSTR_VAL(Z_OBJCE_P(property)->name) :
zend_get_type_by_const(Z_TYPE_P(property)));
- return FAILURE;
+ return FAILURE;
}
- } else if (!ZEND_SAME_FAKE_TYPE(optional_type, Z_TYPE_P(property))) {
- zend_throw_exception_ex(zend_ce_type_error, optional_type,
+ } else if (Z_TYPE_P(property) != IS_UNDEF && !ZEND_SAME_FAKE_TYPE(optional_type,
Z_TYPE_P(property))) {
+ zend_error(E_COMPILE_ERROR,
"Type of %s::$%s must be %s, %s used",
ZSTR_VAL(ce->name),
ZSTR_VAL(name),