@@ -1587,6 +1587,28 @@ ZEND_API void object_properties_init_ex(zend_object *object, HashTable *properti
1587
1587
}
1588
1588
/* }}} */
1589
1589
1590
+ ZEND_API zend_never_inline void zend_forbidden_dynamic_property (zend_class_entry * ce , zend_string * member ) {
1591
+ zend_throw_error (NULL , "Cannot create dynamic property %s::$%s" ,
1592
+ ZSTR_VAL (ce -> name ), ZSTR_VAL (member ));
1593
+ }
1594
+
1595
+ ZEND_API zend_never_inline bool zend_deprecated_dynamic_property (zend_object * obj , zend_string * member ) {
1596
+ GC_ADDREF (obj );
1597
+ zend_error (E_DEPRECATED , "Creation of dynamic property %s::$%s is deprecated" ,
1598
+ ZSTR_VAL (obj -> ce -> name ), ZSTR_VAL (member ));
1599
+ if (UNEXPECTED (GC_DELREF (obj ) == 0 )) {
1600
+ zend_class_entry * ce = obj -> ce ;
1601
+ zend_objects_store_del (obj );
1602
+ if (!EG (exception )) {
1603
+ /* We cannot continue execution and have to throw an exception */
1604
+ zend_throw_error (NULL , "Cannot create dynamic property %s::$%s" ,
1605
+ ZSTR_VAL (ce -> name ), ZSTR_VAL (member ));
1606
+ }
1607
+ return 0 ;
1608
+ }
1609
+ return 1 ;
1610
+ }
1611
+
1590
1612
ZEND_API void object_properties_load (zend_object * object , HashTable * properties ) /* {{{ */
1591
1613
{
1592
1614
zval * prop , tmp ;
@@ -1628,13 +1650,31 @@ ZEND_API void object_properties_load(zend_object *object, HashTable *properties)
1628
1650
zend_hash_update (object -> properties , key , & tmp );
1629
1651
}
1630
1652
} else {
1653
+ if (UNEXPECTED (object -> ce -> ce_flags & ZEND_ACC_NO_DYNAMIC_PROPERTIES )) {
1654
+ zend_forbidden_dynamic_property (object -> ce , key );
1655
+ return ;
1656
+ } else if (!(object -> ce -> ce_flags & ZEND_ACC_ALLOW_DYNAMIC_PROPERTIES )) {
1657
+ if (!zend_deprecated_dynamic_property (object , key )) {
1658
+ return ;
1659
+ }
1660
+ }
1661
+
1631
1662
if (!object -> properties ) {
1632
1663
rebuild_object_properties (object );
1633
1664
}
1634
1665
prop = zend_hash_update (object -> properties , key , prop );
1635
1666
zval_add_ref (prop );
1636
1667
}
1637
1668
} else {
1669
+ if (UNEXPECTED (object -> ce -> ce_flags & ZEND_ACC_NO_DYNAMIC_PROPERTIES )) {
1670
+ zend_forbidden_dynamic_property (object -> ce , key );
1671
+ return ;
1672
+ } else if (!(object -> ce -> ce_flags & ZEND_ACC_ALLOW_DYNAMIC_PROPERTIES )) {
1673
+ if (!zend_deprecated_dynamic_property (object , key )) {
1674
+ return ;
1675
+ }
1676
+ }
1677
+
1638
1678
if (!object -> properties ) {
1639
1679
rebuild_object_properties (object );
1640
1680
}
0 commit comments