Hi...
Hi...Charon wrote:
I have looked all over the place and have been unable to figure out
exactly what the :: means or does ?
It's a direct function call to the class. You don't need to create an
object to make this call. A simpler example would be...
class Thing {
function doStuff() {
}
}
I can either create an object and make the call...
$thing = &new Thing();
$thing->doStuff();
....or I could call it directly...
Thing::doStuff();
Here the method is invoked without any Thing object being created in
memory. The catch is that the $this variable will not be available when
we make this type of call. If the class did this...
class Thing {
var $_message;
function doStuff() {
print $this->_message;
}
}
The second type of invocation would fail as $this is undefined.
The :: type of call is called a "static" invocation or "static
dispatch". When we do Thing::doStuff() we know exactly what piece of
code will execute. It will never change.
Suppose we have a class Thang that extends Thing...
class Thang extends Thing { ... }
$thing = &new Thang();
$thing->doStuff();
Do we know that the above code was executed. No we don't because Thang
might have overridden it. This is a "virtual" invocation. It looks like
a method call, but can be switched within the class hierarchy.
A method that is designed to be called statically (so it has no $this
inside) is often called a "static method". They are a lot less flexible
than the virtual dispatch mechanism, so use them wisely.
In fact the PEAR library is a good example of when not to use static
methods. They are used for error handling. Error handling is usually an
application responsibility and should not be dictated by the library.
Extending errors in PEAR packages usually involves unecessary digging in
source code so that they can be reliably wrapped.
yours, Marcus
--
Marcus Baker,
ma****@lastcraft.com,
no***@appo.demon.co.uk