AllowDynamicProperties

Från Wiki.linux.se
Version från den 31 augusti 2024 kl. 07.11 av Admin (diskussion | bidrag) (Skapade sidan med 'he AllowDynamicProperties class ¶ (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 ClassAllowsDynamicPro...')
(skillnad) ← Äldre version | Nuvarande version (skillnad) | Nyare version → (skillnad)
Hoppa till navigering Hoppa till sök

he AllowDynamicProperties class ¶ (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 { }

  1. [\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 See Also ¶ Attributes overview

Table of Contents ¶ AllowDynamicProperties::__construct — Construct a new AllowDynamicProperties attribute instance