com php-src: disallow typed static properties, throw core errors for internal class stuff: Zend/tests/type_declarations/typed_pr operties_023.phpt
Zend/zend_API.c Zend/zend _compile.c Zend/zend_execute.c
| From: | Bob Weinand | Date: | Wed, 09 Mar 2016 14:31:23 +0000 |
| Subject: | com php-src: disallow typed static properties, throw core errors for internal class stuff: Zend/tests/type_declarations/typed_pr operties_023.phpt Zend/zend_API.c Zend/zend _compile.c Zend/zend_execute.c |
||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-95696@lists.php.net to get a copy of this message | ||
Commit: fb4f14f4cbe9d8442bbd24a0b9928c17c00975c2
Author: Joe Watkins <krakjoe@php.net> Wed, 9 Mar 2016 14:31:23 +0000
Parents: 1d8a9d7e38f54de99fcf568f6dd741e626a99e8d
Branches: typed_ref_properties
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=fb4f14f4cbe9d8442bbd24a0b9928c17c00975c2
Log:
disallow typed static properties, throw core errors for internal class stuff
Changed paths:
A Zend/tests/type_declarations/typed_properties_023.phpt
M Zend/zend_API.c
M Zend/zend_compile.c
M Zend/zend_execute.c
Diff:
diff --git a/Zend/tests/type_declarations/typed_properties_023.phpt
b/Zend/tests/type_declarations/typed_properties_023.phpt
new file mode 100644
index 0000000..b99eef9
--- /dev/null
+++ b/Zend/tests/type_declarations/typed_properties_023.phpt
@@ -0,0 +1,21 @@
+--TEST--
+Test typed properties disallow static
+--FILE--
+<?php
+class Foo {
+ public static int $thing;
+}
+
+$foo = new Foo();
+
+var_dump($foo->bar);
+?>
+--EXPECTF--
+Fatal error: Typed property Foo::$thing must not be static in %s on line 3
+
+
+
+
+
+
+
diff --git a/Zend/zend_API.c b/Zend/zend_API.c
index 1cc7fda..d687fb5 100644
--- a/Zend/zend_API.c
+++ b/Zend/zend_API.c
@@ -3610,19 +3610,15 @@ ZEND_API int zend_declare_typed_property(zend_class_entry *ce, zend_string
*name
{
zend_property_info *property_info, *property_info_ptr;
- if (ce->type == ZEND_INTERNAL_CLASS) {
- property_info = pemalloc(sizeof(zend_property_info), 1);
- if ((access_type & ZEND_ACC_STATIC) || Z_CONSTANT_P(property)) {
- ce->ce_flags &= ~ZEND_ACC_CONSTANTS_UPDATED;
- }
- } else {
- property_info = zend_arena_alloc(&CG(arena), sizeof(zend_property_info));
- if (Z_CONSTANT_P(property)) {
- ce->ce_flags &= ~ZEND_ACC_CONSTANTS_UPDATED;
+ if (optional_type) {
+ if (access_type & ZEND_ACC_STATIC) {
+ zend_error(ce->type == ZEND_USER_CLASS ? E_COMPILE_ERROR : E_CORE_ERROR,
+ "Typed property %s::$%s must not be static",
+ ZSTR_VAL(ce->name),
+ ZSTR_VAL(name));
+ return FAILURE;
}
- }
- if (optional_type) {
switch (Z_TYPE_P(property)) {
case IS_UNDEF:
case IS_CONSTANT:
@@ -3644,6 +3640,18 @@ ZEND_API int zend_declare_typed_property(zend_class_entry *ce, zend_string
*name
ce->ce_flags |= ZEND_ACC_HAS_TYPE_HINTS;
}
+ if (ce->type == ZEND_INTERNAL_CLASS) {
+ property_info = pemalloc(sizeof(zend_property_info), 1);
+ if ((access_type & ZEND_ACC_STATIC) || Z_CONSTANT_P(property)) {
+ ce->ce_flags &= ~ZEND_ACC_CONSTANTS_UPDATED;
+ }
+ } else {
+ property_info = zend_arena_alloc(&CG(arena), sizeof(zend_property_info));
+ if (Z_CONSTANT_P(property)) {
+ ce->ce_flags &= ~ZEND_ACC_CONSTANTS_UPDATED;
+ }
+ }
+
if (Z_ISUNDEF_P(property)) {
ZVAL_NULL(property);
}
diff --git a/Zend/zend_compile.c b/Zend/zend_compile.c
index 0803ab1..a72909e 100644
--- a/Zend/zend_compile.c
+++ b/Zend/zend_compile.c
@@ -5327,6 +5327,13 @@ void zend_compile_prop_decl(zend_ast *ast) /* {{{ */
zend_string *optional_type_name = NULL;
if (type_ast) {
+ if (flags & ZEND_ACC_STATIC) {
+ zend_error_noreturn(ce->type == ZEND_USER_CLASS ? E_COMPILE_ERROR : E_CORE_ERROR,
+ "Typed property %s::$%s must not be static",
+ ZSTR_VAL(ce->name),
+ ZSTR_VAL(name));
+ }
+
use_optional_types = 1;
if (type_ast->kind == ZEND_AST_TYPE) {
optional_type = type_ast->attr;
diff --git a/Zend/zend_execute.c b/Zend/zend_execute.c
index ac0f4a6..d071590 100644
--- a/Zend/zend_execute.c
+++ b/Zend/zend_execute.c
@@ -801,7 +801,7 @@ zend_bool zend_verify_property_type(zend_class_entry *scope, zend_string *name,
ZSTR_VAL(Z_OBJCE_P(property)->name) :
zend_get_type_by_const(Z_TYPE_P(property)));
} else {
- zend_error(E_COMPILE_ERROR,
+ zend_error(scope->type == ZEND_USER_CLASS ? E_COMPILE_ERROR : E_CORE_ERROR,
"Typed property %s::$%s must be an instance of %s, %s used",
ZSTR_VAL(scope->name),
ZSTR_VAL(name),
@@ -829,7 +829,7 @@ zend_bool zend_verify_property_type(zend_class_entry *scope, zend_string *name,
ZSTR_VAL(Z_OBJCE_P(property)->name) :
zend_get_type_by_const(Z_TYPE_P(property)));
} else {
- zend_error(E_COMPILE_ERROR,
+ zend_error(scope->type == ZEND_USER_CLASS ? E_COMPILE_ERROR : E_CORE_ERROR,
"Typed property %s::$%s must be %s, %s used",
ZSTR_VAL(scope->name),
ZSTR_VAL(name),