|
-
Apr 4th, 2008, 08:30 PM
#1
Thread Starter
WiggleWiggle
classes question
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
My usual boring signature: Something
-
Apr 5th, 2008, 10:57 AM
#2
Fanatic Member
Re: classes question
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
-
Apr 5th, 2008, 03:30 PM
#3
Thread Starter
WiggleWiggle
Re: classes question
thanks for that. The link helped a little
My usual boring signature: Something
-
Apr 5th, 2008, 04:04 PM
#4
Re: classes question
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.
-
Apr 5th, 2008, 04:33 PM
#5
Thread Starter
WiggleWiggle
Re: classes question
that confused me even more. Can you use like... gummy worms or something?
My usual boring signature: Something
-
Apr 5th, 2008, 04:35 PM
#6
Re: classes question
What is confusing? It is analogy . Just replace kettle with gummy worms?
-
Apr 5th, 2008, 04:40 PM
#7
Thread Starter
WiggleWiggle
Re: classes question
i dont boil water with gummy bears. Go online and explain to me
My usual boring signature: Something
-
Apr 5th, 2008, 06:45 PM
#8
Re: classes question
 Originally Posted by dclamp
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
-
Apr 6th, 2008, 12:37 AM
#9
Re: classes question
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).
-
Apr 6th, 2008, 01:02 AM
#10
Thread Starter
WiggleWiggle
Re: classes question
ok that makes sense to me. Thanks for going over that pena.
My usual boring signature: Something
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|