I am working on a class, and Penagate told me i should use Public Static Function for one of my functions, but i am not sure when i need to use them and when not to use them.
Explain :)
Printable View
I am working on a class, and Penagate told me i should use Public Static Function for one of my functions, but i am not sure when i need to use them and when not to use them.
Explain :)
Static means that function can be called without needing a member variable.
ie
class::function();
However if you don't have public static, you need to use:
$var = new class();
$var->function();
See for more info: http://www.php.net/manual/en/language.oop5.static.php
thanks for that. The link helped a little :)
You own a kettle producing factory (congratulations on your acquisition). To stream line processes you create a plastic mould that determines the shape of a particular model (class) of kettle. From this you can make many kettles (instances) which all boil your water.
Stamped to the outside of each of your moulds is a model number, in order to view this model number you look at the plastic mould. In order to boil water however or look at the serial number of a kettle itself (an instance) you must look at the actual kettle that the mould produced it. The mould does not contain the serial numbers, nor does it boil water.
Thus, a class member (static member) is an attribute or behaviour that is not associated with an object of that class but with the class itself. For example you may wish to use a a common file in which all your classes are serialized after use and restored before use. A static attribute could be used to store the file name and a static function to restore and save the instances of that class.
that confused me even more. Can you use like... gummy worms or something?
What is confusing? It is analogy :D. Just replace kettle with gummy worms? :confused:
i dont boil water with gummy bears. Go online and explain to me
I swear I wrote that post in English but clearly you are reading too far into it or you have interpreted it as Panda :DQuote:
Originally Posted by dclamp
User class deals with users. Some functions don't apply to any particular user but either to the set of all users as a whole, or to no users: these should be static members. Some functions apply to one particular user: these should be non-static.
Some examples: add user (static, because it results in a new user object), delete user (non-static, because you have a user object to begin with), authenticate (could be either static or non-static, depending on your personal design preference), log out (non-static).
ok that makes sense to me. Thanks for going over that pena.