Home  >  Q&A  >  body text

php - How to use public public methods and public static static public methods in a class?

When to use public function xxxx in a class
When to use public static function xxx
Usually when writing classes, it is basically public function xxxx,
Because I am not very familiar with public static function xxx I understand, so I have basically never used it.
Could you please explain it in detail?

天蓬老师天蓬老师2737 days ago900

reply all(2)I'll reply

  • PHPz

    PHPz2017-05-16 13:17:33

    static is a static method that can be called directly using Class::functionName() without instantiation. At the same time, static methods are stored in the cache and are very fast. Public non-static methods need to be instantiated with new before they can be called using $class->functionName().

    reply
    0
  • 曾经蜡笔没有小新

    曾经蜡笔没有小新2017-05-16 13:17:33

    If your class is only instantiated once and used again, there will be no difference in use.
    If there is a static method, you can call this method directly without instantiating the class.

    reply
    0
  • Cancelreply