Methods are functions defined within a class declaration. They are of two types, those which can be accessed without first declaring an instance of the class and those which can only be accessed by an instance of a class.
Ruby calls the first type a “class method” and the second type an “instance method”. It implements them this way:
class Example def Example.class_method end def instance_method end end
and calls them this way:
result = Example.class_method example = Example.new result = example.instance_method
PHP calls the first type a “public static” method and the second type is just a function.
<?php class Example { public static function class_method() { // You can't use $this in a class method. // You can't use -> to refer to a class method. You must use :: } function instance_method() { } } ?>
and calls them this way:
<?php $result = Example::class_method(); $example = new Example; $result = $example->instance_method(); ?>
More information about class methods (and class variables) is in the PHP manual under Scope Resolution Operator (::).