Skip to content

AllowDynamicProperties for inherited classes #5440

@braandl

Description

@braandl

Affected page

https://www.php.net/manual/en/class.allowdynamicproperties.php

Current issue

The current example does not explain what happens, when you inherit from a class, defining #[\AllowDynamicProperties] attribute.

Suggested improvement

Therefore i'd suggest to use the following, extended example:

<?php

class DefaultBehaviour { }

#[\AllowDynamicProperties]
class ClassAllowsDynamicProperties { }


class InheritedClassAllowsDynamicProperties extends ClassAllowsDynamicProperties { }

$o1 = new DefaultBehaviour();
$o2 = new ClassAllowsDynamicProperties();
$o3 = new InheritedClassAllowsDynamicProperties();

$o1->nonExistingProp = true;
$o2->nonExistingProp = true;
$o3->nonExistingProp = true;
?>

The output is still identical to the current version.

Additional context (optional)

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions