On 04/10/2014 17:10, Thomas Gossmann wrote:
Hence, for php-beginners, this example of a simple class is a good
start, which can also be used educating them in OOP by adding the more
advanced parts - instead of letting them write function when this
actually is a method (In my eyes, education failed here).
I'm not sure there is really as clear-cut a distinction as you imply
here, such that the word function is "wrong" when used for a method.
PHP has 4 different types of "sub-routines" (unless I've forgotten one):
- global "functions", which needn't return anything, so encompass what
some languages call "procedures"
- object/instance "methods", which are "virtual" (polymorphic),
inheritable and overridable subroutines called on an instance, with the
magic variable $this defined
- "static methods", which have the same inheritance and overriding
semantics as methods, and have access to private and protected members
of the class, but do not require an instance, and do not define $this
- "anonymous functions", or "closures", which are actually a complete
object encapsulating both code and state
Different languages call these concepts, and other variations on the
same themes, by various names. In PHP, they are all introduced by the
keyword "function", which indicates "here begins a sub-routine declaration".
--
Rowan Collins
[IMSoP]
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php