@@ -1586,6 +1586,28 @@ ZEND_API void object_properties_init_ex(zend_object *object, HashTable *properti
1586
1586
}
1587
1587
/* }}} */
1588
1588
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
+
1589
1611
ZEND_API void object_properties_load (zend_object * object , HashTable * properties ) /* {{{ */
1590
1612
{
1591
1613
zval * prop , tmp ;
@@ -1627,13 +1649,31 @@ ZEND_API void object_properties_load(zend_object *object, HashTable *properties)
1627
1649
zend_hash_update (object -> properties , key , & tmp );
1628
1650
}
1629
1651
} else {
1652
+ if (UNEXPECTED (object -> ce -> ce_flags & ZEND_ACC_NO_DYNAMIC_PROPERTIES )) {
1653
+ zend_forbidden_dynamic_property (object -> ce , key );
1654
+ return ;
1655
+ } else if (!(object -> ce -> ce_flags & ZEND_ACC_ALLOW_DYNAMIC_PROPERTIES )) {
1656
+ if (!zend_deprecated_dynamic_property (object , key )) {
1657
+ return ;
1658
+ }
1659
+ }
1660
+
1630
1661
if (!object -> properties ) {
1631
1662
rebuild_object_properties (object );
1632
1663
}
1633
1664
prop = zend_hash_update (object -> properties , key , prop );
1634
1665
zval_add_ref (prop );
1635
1666
}
1636
1667
} else {
1668
+ if (UNEXPECTED (object -> ce -> ce_flags & ZEND_ACC_NO_DYNAMIC_PROPERTIES )) {
1669
+ zend_forbidden_dynamic_property (object -> ce , key );
1670
+ return ;
1671
+ } else if (!(object -> ce -> ce_flags & ZEND_ACC_ALLOW_DYNAMIC_PROPERTIES )) {
1672
+ if (!zend_deprecated_dynamic_property (object , key )) {
1673
+ return ;
1674
+ }
1675
+ }
1676
+
1637
1677
if (!object -> properties ) {
1638
1678
rebuild_object_properties (object );
1639
1679
}
0 commit comments