Skip to content

Commit 36087c2

Browse files
committed
Fix tests and review suggestions
1 parent 2de79fe commit 36087c2

18 files changed

+57
-43
lines changed

Zend/zend_API.c

+8-30
Original file line numberDiff line numberDiff line change
@@ -1586,28 +1586,6 @@ ZEND_API void object_properties_init_ex(zend_object *object, HashTable *properti
15861586
}
15871587
/* }}} */
15881588

1589-
ZEND_API zend_never_inline void zend_forbidden_dynamic_property(zend_class_entry *ce, zend_string *member) {
1590-
zend_throw_error(NULL, "Cannot create dynamic property %s::$%s",
1591-
ZSTR_VAL(ce->name), ZSTR_VAL(member));
1592-
}
1593-
1594-
ZEND_API zend_never_inline bool zend_deprecated_dynamic_property(zend_object *obj, zend_string *member) {
1595-
GC_ADDREF(obj);
1596-
zend_error(E_DEPRECATED, "Creation of dynamic property %s::$%s is deprecated",
1597-
ZSTR_VAL(obj->ce->name), ZSTR_VAL(member));
1598-
if (UNEXPECTED(GC_DELREF(obj) == 0)) {
1599-
zend_class_entry *ce = obj->ce;
1600-
zend_objects_store_del(obj);
1601-
if (!EG(exception)) {
1602-
/* We cannot continue execution and have to throw an exception */
1603-
zend_throw_error(NULL, "Cannot create dynamic property %s::$%s",
1604-
ZSTR_VAL(ce->name), ZSTR_VAL(member));
1605-
}
1606-
return 0;
1607-
}
1608-
return 1;
1609-
}
1610-
16111589
ZEND_API void object_properties_load(zend_object *object, HashTable *properties) /* {{{ */
16121590
{
16131591
zval *prop, tmp;
@@ -1650,12 +1628,12 @@ ZEND_API void object_properties_load(zend_object *object, HashTable *properties)
16501628
}
16511629
} else {
16521630
if (UNEXPECTED(object->ce->ce_flags & ZEND_ACC_NO_DYNAMIC_PROPERTIES)) {
1653-
zend_forbidden_dynamic_property(object->ce, key);
1631+
zend_throw_error(NULL, "Cannot create dynamic property %s::$%s",
1632+
ZSTR_VAL(object->ce->name), zend_get_unmangled_property_name(key));
16541633
return;
16551634
} else if (!(object->ce->ce_flags & ZEND_ACC_ALLOW_DYNAMIC_PROPERTIES)) {
1656-
if (!zend_deprecated_dynamic_property(object, key)) {
1657-
return;
1658-
}
1635+
zend_error(E_DEPRECATED, "Creation of dynamic property %s::$%s is deprecated",
1636+
ZSTR_VAL(object->ce->name), zend_get_unmangled_property_name(key));
16591637
}
16601638

16611639
if (!object->properties) {
@@ -1666,12 +1644,12 @@ ZEND_API void object_properties_load(zend_object *object, HashTable *properties)
16661644
}
16671645
} else {
16681646
if (UNEXPECTED(object->ce->ce_flags & ZEND_ACC_NO_DYNAMIC_PROPERTIES)) {
1669-
zend_forbidden_dynamic_property(object->ce, key);
1647+
zend_throw_error(NULL, "Cannot create dynamic property %s::$%s",
1648+
ZSTR_VAL(object->ce->name), zend_get_unmangled_property_name(key));
16701649
return;
16711650
} else if (!(object->ce->ce_flags & ZEND_ACC_ALLOW_DYNAMIC_PROPERTIES)) {
1672-
if (!zend_deprecated_dynamic_property(object, key)) {
1673-
return;
1674-
}
1651+
zend_error(E_DEPRECATED, "Creation of dynamic property %s::$%s is deprecated",
1652+
ZSTR_VAL(object->ce->name), zend_get_unmangled_property_name(key));
16751653
}
16761654

16771655
if (!object->properties) {

Zend/zend_API.h

-2
Original file line numberDiff line numberDiff line change
@@ -522,8 +522,6 @@ ZEND_API zend_result object_init_ex(zval *arg, zend_class_entry *ce);
522522
ZEND_API zend_result object_and_properties_init(zval *arg, zend_class_entry *ce, HashTable *properties);
523523
ZEND_API void object_properties_init(zend_object *object, zend_class_entry *class_type);
524524
ZEND_API void object_properties_init_ex(zend_object *object, HashTable *properties);
525-
ZEND_API zend_never_inline void zend_forbidden_dynamic_property(zend_class_entry *ce, zend_string *member);
526-
ZEND_API zend_never_inline bool zend_deprecated_dynamic_property(zend_object *obj, zend_string *member);
527525
ZEND_API void object_properties_load(zend_object *object, HashTable *properties);
528526

529527
ZEND_API void zend_merge_properties(zval *obj, HashTable *properties);

Zend/zend_object_handlers.c

+22
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,28 @@ static ZEND_COLD zend_never_inline void zend_bad_property_name(void) /* {{{ */
275275
}
276276
/* }}} */
277277

278+
ZEND_API zend_never_inline void zend_forbidden_dynamic_property(zend_class_entry *ce, zend_string *member) {
279+
zend_throw_error(NULL, "Cannot create dynamic property %s::$%s",
280+
ZSTR_VAL(ce->name), ZSTR_VAL(member));
281+
}
282+
283+
ZEND_API zend_never_inline bool zend_deprecated_dynamic_property(zend_object *obj, zend_string *member) {
284+
GC_ADDREF(obj);
285+
zend_error(E_DEPRECATED, "Creation of dynamic property %s::$%s is deprecated",
286+
ZSTR_VAL(obj->ce->name), ZSTR_VAL(member));
287+
if (UNEXPECTED(GC_DELREF(obj) == 0)) {
288+
zend_class_entry *ce = obj->ce;
289+
zend_objects_store_del(obj);
290+
if (!EG(exception)) {
291+
/* We cannot continue execution and have to throw an exception */
292+
zend_throw_error(NULL, "Cannot create dynamic property %s::$%s",
293+
ZSTR_VAL(ce->name), ZSTR_VAL(member));
294+
}
295+
return 0;
296+
}
297+
return 1;
298+
}
299+
278300
static ZEND_COLD zend_never_inline void zend_readonly_property_modification_scope_error(
279301
zend_class_entry *ce, zend_string *member, zend_class_entry *scope, const char *operation) {
280302
zend_throw_error(NULL, "Cannot %s readonly property %s::$%s from %s%s",

ext/gmp/tests/serialize.phpt

+2
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ object(GMP)#%d (1) {
5252
string(2) "42"
5353
}
5454

55+
Deprecated: Creation of dynamic property GMP::$foo is deprecated in %s on line %d
56+
5557
Deprecated: Creation of dynamic property GMP::$foo is deprecated in %s on line %d
5658
string(56) "O:3:"GMP":2:{i:0;s:1:"d";i:1;a:1:{s:3:"foo";s:3:"bar";}}"
5759
object(GMP)#%d (2) {

ext/session/tests/003.phpt

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ error_reporting(E_ALL);
1616

1717
class foo {
1818
public $bar = "ok";
19+
public $yes;
1920
function method() { $this->yes++; }
2021
}
2122

ext/session/tests/004.phpt

+1
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ $hnd = new handler;
5252

5353
class foo {
5454
public $bar = "ok";
55+
public $yes;
5556
function method() { $this->yes++; }
5657
}
5758

ext/session/tests/005.phpt

+1
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ $hnd = new handler;
5353

5454
class foo {
5555
public $bar = "ok";
56+
public $yes;
5657
function method() { $this->yes++; }
5758
}
5859

ext/session/tests/023.phpt

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ error_reporting(E_ALL);
1616

1717
class foo {
1818
public $bar = "ok";
19+
public $yes;
1920
function method() { $this->yes++; }
2021
}
2122

ext/session/tests/024.phpt

+1
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ $hnd = new handler;
5353

5454
class foo {
5555
public $bar = "ok";
56+
public $yes;
5657
function method() { $this->yes++; }
5758
}
5859

ext/session/tests/025.phpt

+1
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ $hnd = new handler;
5454

5555
class foo {
5656
public $bar = "ok";
57+
public $yes;
5758
function method() { $this->yes++; }
5859
}
5960

ext/soap/tests/bug70388.phpt

+4
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ soap
55
--FILE--
66
<?php
77
class MySoapClient extends SoapClient {
8+
public $uri;
9+
public $location;
10+
public $__default_headers;
11+
812
public function __doRequest($request, $location, $action, $version, $one_way = 0): string {
913
echo $request, "\n";
1014
return '';

ext/soap/tests/bugs/bug69085.phpt

+4
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ soap.wsdl_cache_enabled=0
88
<?php
99

1010
class MySoapClient extends SoapClient {
11+
public $uri;
12+
public $location;
13+
public $__default_headers;
14+
1115
public function __doRequest($request, $location, $action, $version, $one_way = 0): string {
1216
echo $request, "\n";
1317
return '';

ext/standard/tests/serialize/bug49649.phpt

+2-2
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@ $class = unserialize(base64_decode($serialized));
3434
var_dump($class);
3535
?>
3636
--EXPECTF--
37-
Deprecated: Creation of dynamic property Foo::$ is deprecated in %s on line %d
37+
Deprecated: Creation of dynamic property Foo::$private is deprecated in %s on line %d
3838

39-
Deprecated: Creation of dynamic property Foo::$ is deprecated in %s on line %d
39+
Deprecated: Creation of dynamic property Foo::$protected is deprecated in %s on line %d
4040

4141
Deprecated: Creation of dynamic property Foo::$notThere is deprecated in %s on line %d
4242
object(Foo)#1 (4) {

ext/standard/tests/serialize/bug49649_1.phpt

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ $class = unserialize(base64_decode($serialized));
3434
var_dump($class);
3535
?>
3636
--EXPECTF--
37-
Deprecated: Creation of dynamic property Foo::$ is deprecated in %s on line %d
37+
Deprecated: Creation of dynamic property Foo::$private is deprecated in %s on line %d
3838

3939
Deprecated: Creation of dynamic property Foo::$public is deprecated in %s on line %d
4040

ext/standard/tests/serialize/bug49649_2.phpt

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ $class = unserialize(base64_decode($serialized));
3434
var_dump($class);
3535
?>
3636
--EXPECTF--
37-
Deprecated: Creation of dynamic property Foo::$ is deprecated in %s on line %d
37+
Deprecated: Creation of dynamic property Foo::$protected is deprecated in %s on line %d
3838

3939
Deprecated: Creation of dynamic property Foo::$public is deprecated in %s on line %d
4040

ext/standard/tests/serialize/unserialize_overwrite_undeclared_protected.phpt

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ STR;
1313
var_dump(unserialize($str));
1414
?>
1515
--EXPECTF--
16-
Deprecated: Creation of dynamic property Test::$ is deprecated in %s on line %d
16+
Deprecated: Creation of dynamic property Test::$x is deprecated in %s on line %d
1717
object(Test)#1 (2) {
1818
["foo"]=>
1919
NULL

ext/standard/tests/serialize/unserialize_ref_to_overwritten_declared_prop.phpt

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ Trying to create a reference to an overwritten declared property
33
--FILE--
44
<?php
55
$str = <<<STR
6-
O:5:"Error":2:{S:8:"previous";N;S:8:"previous";R:2;}
6+
O:9:"Attribute":1:{s:5:"flags";i:63;s:5:"flags";R:2}
77
STR;
88
var_dump(unserialize($str));
99
?>
1010
--EXPECTF--
11-
Notice: unserialize(): Error at offset 51 of 52 bytes in %s on line %d
11+
Notice: unserialize(): Error at offset 36 of 52 bytes in %s on line %d
1212
bool(false)

ext/standard/var_unserializer.re

+4-4
Original file line numberDiff line numberDiff line change
@@ -639,12 +639,12 @@ declared_property:
639639
}
640640
} else {
641641
if (UNEXPECTED(obj->ce->ce_flags & ZEND_ACC_NO_DYNAMIC_PROPERTIES)) {
642-
zend_forbidden_dynamic_property(obj->ce, Z_STR_P(&key));
642+
zend_throw_error(NULL, "Cannot create dynamic property %s::$%s",
643+
ZSTR_VAL(obj->ce->name), zend_get_unmangled_property_name(Z_STR_P(&key)));
643644
goto failure;
644645
} else if (!(obj->ce->ce_flags & ZEND_ACC_ALLOW_DYNAMIC_PROPERTIES)) {
645-
if (!zend_deprecated_dynamic_property(obj, Z_STR_P(&key))) {
646-
goto failure;
647-
}
646+
zend_error(E_DEPRECATED, "Creation of dynamic property %s::$%s is deprecated",
647+
ZSTR_VAL(obj->ce->name), zend_get_unmangled_property_name(Z_STR_P(&key)));
648648
}
649649

650650
int ret = is_property_visibility_changed(obj->ce, &key);

0 commit comments

Comments
 (0)