Longhorn PHP 2025 - Call For Papers

The AllowDynamicProperties attribute

(PHP 8 >= 8.2.0)

Introduction

This attribute is used to mark classes that allow dynamic properties.

Class synopsis

final class AllowDynamicProperties {
/* Methods */
public __construct()
}

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.

<?php
class DefaultBehaviour { }

#[
\AllowDynamicProperties]
class
ClassAllowsDynamicProperties { }

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

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

Output of the above example in PHP 8.2:

Deprecated: Creation of dynamic property DefaultBehaviour::$nonExistingProp is deprecated in file on line 10

Table of Contents

add a note

User Contributed Notes

There are no user contributed notes for this page.
To Top

Follow Lee on X/Twitter - Father, Husband, Serial builder creating AI, crypto, games & web tools. We are friends :) AI Will Come To Life!

Check out: eBank.nz (Art Generator) | Netwrck.com (AI Tools) | Text-Generator.io (AI API) | BitBank.nz (Crypto AI) | ReadingTime (Kids Reading) | RewordGame | BigMultiplayerChess | WebFiddle | How.nz | Helix AI Assistant