I am coming from the Ruby world and I have a PHP project I currently work on.
Like in Ruby scripts, is it possible to declare class methods in PHP? Basically, I’m asking what the equivalent of the following code would be in PHP
class A
def hello; "hello from object"; end
def self.hello; "hello from class"; end
end
Note the difference between the instance method and the class method.
In PHP class methods are usually referred to as static methods and are declared as such. To directly translate your example:-
Then you would call the methods like this:-
You can also have static properties, so the above example could be modified something like this:-
http://php.net/manual/en/language.oop5.static.php