com php-src: "string" mat be also a valid "callable": Zend/tests/type_declarations/typed_properties_053 .phpt
Zend/tests/type_declarations/typed_properties_ 054.phpt Zend/zend_compile.c
| From: | Bob Weinand | Date: | Wed, 25 May 2016 10:50:40 +0000 |
| Subject: | com php-src: "string" mat be also a valid "callable": Zend/tests/type_declarations/typed_properties_053 .phpt Zend/tests/type_declarations/typed_properties_ 054.phpt Zend/zend_compile.c |
||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-95526@lists.php.net to get a copy of this message | ||
Commit: 40aa6c247c410da42badcf765a324a1d731859a5
Author: Dmitry Stogov <dmitry@zend.com> Wed, 25 May 2016 13:50:40 +0300
Parents: 291d4315a65e7939341a121c369ab5c935d40765
Branches: typed_ref_properties
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=40aa6c247c410da42badcf765a324a1d731859a5
Log:
"string" mat be also a valid "callable"
Changed paths:
A Zend/tests/type_declarations/typed_properties_053.phpt
A Zend/tests/type_declarations/typed_properties_054.phpt
M Zend/zend_compile.c
Diff:
diff --git a/Zend/tests/type_declarations/typed_properties_053.phpt
b/Zend/tests/type_declarations/typed_properties_053.phpt
new file mode 100644
index 0000000..6fb2519
--- /dev/null
+++ b/Zend/tests/type_declarations/typed_properties_053.phpt
@@ -0,0 +1,26 @@
+--TEST--
+Default values of callable properties
+--FILE--
+<?php
+class A {
+ public callable $a1;
+ public callable $a2 = "foo";
+ public callable $a3 = array("A","bar");
+}
+$obj = new A;
+var_dump($obj);
+?>
+--EXPECT--
+object(A)#1 (2) {
+ ["a1"]=>
+ uninitialized(callable)
+ ["a2"]=>
+ string(3) "foo"
+ ["a3"]=>
+ array(2) {
+ [0]=>
+ string(1) "A"
+ [1]=>
+ string(3) "bar"
+ }
+}
diff --git a/Zend/tests/type_declarations/typed_properties_054.phpt
b/Zend/tests/type_declarations/typed_properties_054.phpt
new file mode 100644
index 0000000..9155bcc
--- /dev/null
+++ b/Zend/tests/type_declarations/typed_properties_054.phpt
@@ -0,0 +1,12 @@
+--TEST--
+Default values of callable properties
+--FILE--
+<?php
+class A {
+ public callable $a1 = 42;
+}
+$obj = new A;
+var_dump($obj);
+?>
+--EXPECTF--
+Fatal error: Default value for properties with callable type can only be a string or an array in
%styped_properties_054.php on line 3
\ No newline at end of file
diff --git a/Zend/zend_compile.c b/Zend/zend_compile.c
index 24a9621..949da44 100644
--- a/Zend/zend_compile.c
+++ b/Zend/zend_compile.c
@@ -5598,9 +5598,9 @@ void zend_compile_prop_decl(zend_ast *ast, zend_ast *type_ast) /* {{{ */
"Default value for properties with array type can only be an array");
}
} else if (optional_type == IS_CALLABLE) {
- if (Z_TYPE(value_zv) != IS_ARRAY) {
+ if (Z_TYPE(value_zv) != IS_STRING && Z_TYPE(value_zv) != IS_ARRAY) {
zend_error_noreturn(E_COMPILE_ERROR,
- "Default value for properties with callable type can only be an array");
+ "Default value for properties with callable type can only be a string or an
array");
}
} else if (optional_type == IS_OBJECT) {
zend_error_noreturn(E_COMPILE_ERROR,