diff --git a/language/oop5/properties.xml b/language/oop5/properties.xml index 2516f3942e7a..80781b754b3e 100644 --- a/language/oop5/properties.xml +++ b/language/oop5/properties.xml @@ -334,16 +334,12 @@ $test->obj = new stdClass; This dynamically created property will only be available on this class instance. - + + Dynamic properties are supported by stdClass and its subclasses. Other classes may enable similar behavior with AllowDynamicProperties or property overloading. + - Dynamic properties are deprecated as of PHP 8.2.0. - It is recommended to declare the property instead. - To handle arbitrary property names, the class should implement the magic - methods __get() and - __set(). - At last resort the class can be marked with the - #[\AllowDynamicProperties] attribute. + Prior to PHP 8.2.0, all classes supported dynamic properties. This is deprecated. By default, accessing an undeclared property will emit a deprecation warning. diff --git a/language/predefined/attributes/allowdynamicproperties.xml b/language/predefined/attributes/allowdynamicproperties.xml index 7cefa2d8a384..584c0f60427d 100644 --- a/language/predefined/attributes/allowdynamicproperties.xml +++ b/language/predefined/attributes/allowdynamicproperties.xml @@ -11,6 +11,12 @@ This attribute is used to mark classes that allow dynamic properties. + + + Prior to PHP 8.2.0, all classes implicitly allowed dynamic properties. + Implicit creation of dynamic properties is now deprecated. + +
@@ -38,32 +44,43 @@
&reftitle.examples; - - Dynamic properties are deprecated as of PHP 8.2.0, - thus using them without marking the class with this attribute will emit - a deprecation notice. - + + To enable dynamic properties, add #[\AllowDynamicProperties]. + myDynamicProp = 1234; +?> +]]> + + + + + + As of PHP 8.2.0, the declaration is required. If the declaration is omitted + and an undeclared property is accessed, PHP will raise a warning. + + + +nonExistingProp = true; -$o2->nonExistingProp = true; +$obj = new InvalidExample(); +$obj->myUnknownProperty = 1234; ?> ]]> &example.outputs.82;