FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » static vs global variable
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
Re: static vs global variable [message #172697 is a reply to message #172694] Sat, 26 February 2011 13:13 Go to previous messageGo to previous message
sheldonlg is currently offline  sheldonlg
Messages: 166
Registered: September 2010
Karma:
Senior Member
On 2/25/2011 7:40 PM, tobycraftse(at)yahoo(dot)com wrote:
>
> if I have a couple of variable want to included by many php file
>
> should i use global or static class variable?
>
> global is kinda trouble as i need to delcare global every php file i
> want to use it.
>
> static variable do not need to declare up front

The only globals I would EVER use are the super-globals such as $_SESSION.

So far the only real use I have found for a static class variable is in
setting it once when the class instance is first created. Then, other
invocations would be via a ClassName::getInstance() to return the
already created instance of the class by testing for that variable not
being NULL.

Any other variable that is needed that from that class would be obtained
from a mutator method such as getThisVariable() which would return the
class variable $thisVariable.

So, there is really only one static class variable and the rest are
ordinary class variables with methods provided for their access from the
outside once the instance is retrieved.

--
Shelly
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Stats comp.lang.php (last 7 days)
Next Topic: ODBC Connection
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Tue Nov 26 21:16:07 GMT 2024

Total time taken to generate the page: 0.04544 seconds