PHP Can static:: replace self::?

后端 未结 2 731
一整个雨季
一整个雨季 2020-11-30 21:01

I am a little confused with this matter. I am designing an ORM class that tries to behave very similarly to ActiveRecord in ruby on rails, but that\'s beside the point.

2条回答
  •  悲哀的现实
    2020-11-30 21:10

    try to use the code bellow to see the difference between self and static:

     ".self::$x."
    "; echo "static => ".static::$x; } } class Child_ extends Parent_{ protected static $x = "child"; } echo "

    using the Parent_ class

    "; Parent_::makeTest(); echo "

    using the Child_ class

    "; Child_::makeTest(); ?>

    and you get this result:

    using the Parent_ class

    • self => parent
    • static => parent

    using the Child_ class

    • self => parent
    • static => child

提交回复
热议问题