以前得DAO,很多属性是动态的,就会报错。

网上很多解决方案,但是很多都是错的


很多是在类前加#[AllowDynamicProperties],而这个就是错的

#[AllowDynamicProperties]
 class User {
     private int $uid;
 }

 $user = new User();
 $user->name = 'Foo';

原文地址:https://php.watch/versions/8.2/dynamic-properties-deprecated#AllowDynamicProperties


正确的是:


#[AllowDynamicProperties]
 class User {
     private int $uid;
 }

 $user = new User();
 $user->name = 'Foo';

原文地址:https://www.ziruchu.com/art/508