Когда мне следует использовать статические методы? ⇐ Php
-
Anonymous
Когда мне следует использовать статические методы?
I have a class that is containing 10 methods. I always need to use one of those methods. Now I want to know, which approach is better?
class cls{ public function func1(){} public function func2(){} . . public function func10(){} } $obj = new cls; $data = $obj->func3(); // it is random, it can be anything (func1, or func9 or ...) OR
class cls{ public static function func1(){} public static function func2(){} . . public static function func10(){} } cls::func3(); // it is random, it can be anything (func1, or func9 or ...)
Источник: https://stackoverflow.com/questions/337 ... ic-methods
I have a class that is containing 10 methods. I always need to use one of those methods. Now I want to know, which approach is better?
class cls{ public function func1(){} public function func2(){} . . public function func10(){} } $obj = new cls; $data = $obj->func3(); // it is random, it can be anything (func1, or func9 or ...) OR
class cls{ public static function func1(){} public static function func2(){} . . public static function func10(){} } cls::func3(); // it is random, it can be anything (func1, or func9 or ...)
Источник: https://stackoverflow.com/questions/337 ... ic-methods
Мобильная версия