Here’s one of my few questions I will post to get a better understanding of OOP.
When is it necessary to use [I]static variables[/I] and [I]static methods[/I] with OOP in PHP? I’m trying to understand the method behind this. I’m open to all kinds of explanations and code representations as well. Thanks
@NogDogJan 18.2011 — #Static variables are used when you want all instances (objects) of that class to be working with the same variable. If one instance changes its value, all other instances will then see it as that value. Additionally, it allows you to access that value without the need of an instantiated object, simply by using the [B]className::$variableName[/B] syntax.
Static methods give you the same access ability: calling the method without an object by using [B]className::objectName()[/B] syntax. This only makes sense (and I think throws a warning or error or exception?) if the static method only references static class variables -- i.e. [b]$this->variableName[/b] would not be legal within that method.
I've not really had much need to use static variables or methods. The few times I have, it's usually been to provide some utility functions wrapped up within a class of related functions: really not OOP so much as organizing some procedural functions in an OOP disguise. ?