Is there a way to have PHP subclasses inherit properties (both static and instance)?

时间秒杀一切 提交于 2019-12-01 18:55:11

Inheritance and static properties does sometime lead to "strange" things in PHP.

You should have a look at Late Static Bindings in the PHP's manual : it explains what can happen when inheriting and using static properties in PHP <= 5.2 ; and gives a solutions for PHP >= 5.3 where you can use the static:: keywords instead of self::, so that static binding is done at execution (and not compile) time.

The answer is "with a workaround".

You have to create a static constructor and have it called to copy the property.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!