Posted by Toby Inkster on 01/13/07 10:05
Sanders Kaufman wrote:
> When I use a class's methods and such, I've been using "->".
> But it seems like this "::" is used the same way.
Using '::' you can call a classes methods, constants and static functions
(here's the key part) without instantiating an object of that class.
Example:
<?php
include "Widget.class.php";
echo Widget::FOO;
?>
Versus:
<?php
include "Widget.class.php";
$my_widget = new Widget();
echo $my_widget->FOO;
?>
Another example:
<?php
class Widget
{
function exist ()
{
return isset($this);
}
}
$my_widget = new Widget();
$my_widget->exist(); // true
Widget::exist(); // false
?>
That is, '->' forces a function to run on a specific object, whereas '::'
runs the function without the object instance (i.e. '$this' is undefined).
--
Toby A Inkster BSc (Hons) ARCS
Contact Me ~ http://tobyinkster.co.uk/contact
[Back to original message]
|