PHP中子类如何调用父类的静态方法

 2721

php中子类调用父类静态方法的方法:【parent::method()】或【self::method()】。如果要在子类外部调用,则使用【子类实例->method()】。


PHP中子类如何调用父类的静态方法


子类内部访问父类静态成员属性或方法

parent::method()/self::method()

注意:$this->staticProperty(父类的静态属性不可以通过$this(子类实例)来访问,会报错:

:PHP Strict Standards: Accessing static property Person::$country as non static in,PHP Notice: Undefined property: )

子类外部访问

子类名::method()

子类实例->method() (静态方法也可以通过普通对象的方式访问)

注意:子类实例->staticProperty(父类的静态属性不可以通过子类实例来访问,会报错:

:PHP Strict Standards: Accessing static property Person::$country as non static in,PHP Notice: Undefined property: )



本文网址:https://www.zztuku.com/detail-7944.html
站长图库 - PHP中子类如何调用父类的静态方法
申明:如有侵犯,请 联系我们 删除。

评论(0)条

您还没有登录,请 登录 后发表评论!

提示:请勿发布广告垃圾评论,否则封号处理!!

    编辑推荐