Deprecated: Optional parameter $keys declared before required parameter $cms_id is implicitly treated as a required parameter in /home/www/dev/work/class/blog/CmsKey.php on line 75

Deprecated: Creation of dynamic property lvesu\lvesu\controller\blog\php::$title is deprecated in /home/www/dev/work/website/lvesu/class/controller/blog/php.php on line 28

Deprecated: Creation of dynamic property lvesu\lvesu\controller\blog\php::$outlink is deprecated in /home/www/dev/work/website/lvesu/template/blog/cms/php.manual.tpl on line 2

Deprecated: Creation of dynamic property lvesu\lvesu\controller\blog\php::$status is deprecated in /home/www/dev/work/website/lvesu/template/blog/index.head.php on line 2
PHP - Manual: AllowDynamicProperties - 互联网笔记

略微加速

PHP官方手册 - 互联网笔记

PHP - Manual: AllowDynamicProperties

2025-05-07

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

参见

注解概览

目录

添加备注

用户贡献的备注

此页面尚无用户贡献的备注。

官方地址:https://www.php.net/manual/en/class.allowdynamicproperties.php

冷却塔厂家 广告
中文GPT4.0无需注册 广告
北京半月雨文化科技有限公司.版权所有 京ICP备12026184号-3