PHP 8.1.28 Released!

AllowDynamicProperties 类

(PHP 8 >= 8.2.0)

简介

此注解用于标记 class,允许动态属性

类摘要

final class AllowDynamicProperties {
/* 方法 */
public __construct()
}

示例

从 PHP 8.2.0 起弃用动态属性,因此在不使用此注解标记类的情况下使用动态属性将发出弃用通知。

<?php
class DefaultBehaviour { }

#[
\AllowDynamicProperties]
class
ClassAllowsDynamicProperties { }

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

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

以上示例在 PHP 8.2 中的输出:

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

参见

注解概览

目录

add a note

User Contributed Notes

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