com php-src: check type on declaration: Zend/zend_API.c Z end/zend_compile.c
| From: | Bob Weinand | Date: | Mon, 07 Mar 2016 14:16:06 +0000 |
| Subject: | com php-src: check type on declaration: Zend/zend_API.c Z end/zend_compile.c | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-95616@lists.php.net to get a copy of this message | ||
Commit: c957e752fd76df95a0002d11dbf1073ebbebfa96
Author: Joe Watkins <krakjoe@php.net> Mon, 7 Mar 2016 14:16:06 +0000
Parents: b557f8ba8e6cd30131e68a2cbbcce9a8cd959448
Branches: typed_ref_properties
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=c957e752fd76df95a0002d11dbf1073ebbebfa96
Log:
check type on declaration
Changed paths:
M Zend/zend_API.c
M Zend/zend_compile.c
Diff:
diff --git a/Zend/zend_API.c b/Zend/zend_API.c
index 96ca7ed..f70b1a7 100644
--- a/Zend/zend_API.c
+++ b/Zend/zend_API.c
@@ -3622,6 +3622,55 @@ ZEND_API int zend_declare_typed_property(zend_class_entry *ce, zend_string
*name
}
}
+ if (optional_type) {
+ /* TODO(krakjoe) not sure about exceptions in [no active file] */
+ if (optional_type == IS_OBJECT) {
+ if (Z_TYPE_P(property) != IS_UNDEF) {
+ zend_string *type_name = optional_type_name;
+
+ if (zend_string_equals_literal_ci(type_name, "parent")) {
+ if (!ce->parent) {
+ zend_throw_exception_ex(zend_ce_type_error, optional_type,
+ "Type of %s::$%s cannot be parent type, no parent scope active",
+ ZSTR_VAL(ce->name),
+ ZSTR_VAL(name));
+ return FAILURE;
+ }
+
+ type_name = ce->parent->name;
+ }
+
+ if (zend_string_equals_literal_ci(type_name, "self")) {
+ 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",
+ 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;
+ }
+ } else if (!ZEND_SAME_FAKE_TYPE(optional_type, Z_TYPE_P(property))) {
+ zend_throw_exception_ex(zend_ce_type_error, optional_type,
+ "Type of %s::$%s must be %s, %s used",
+ ZSTR_VAL(ce->name),
+ ZSTR_VAL(name),
+ zend_get_type_by_const(optional_type),
+ Z_TYPE_P(property) == IS_OBJECT ?
+ ZSTR_VAL(Z_OBJCE_P(property)->name) :
+ zend_get_type_by_const(Z_TYPE_P(property)));
+ return FAILURE;
+ }
+ }
+
+ if (Z_TYPE_P(property) == IS_UNDEF) {
+ ZVAL_NULL(property);
+ }
+
if (!(access_type & ZEND_ACC_PPP_MASK)) {
access_type |= ZEND_ACC_PUBLIC;
}
diff --git a/Zend/zend_compile.c b/Zend/zend_compile.c
index cbda5c1..61faf20 100644
--- a/Zend/zend_compile.c
+++ b/Zend/zend_compile.c
@@ -5374,7 +5374,7 @@ void zend_compile_prop_decl(zend_ast *ast) /* {{{ */
if (value_ast) {
zend_const_expr_to_zval(&value_zv, value_ast);
} else {
- ZVAL_NULL(&value_zv);
+ ZVAL_UNDEF(&value_zv);
}
name = zend_new_interned_string_safe(name);