Static vs. Instantiated Objects in PHP
| From: | Mark Baldwin | Date: | Thu, 20 Apr 2006 18:25:05 +0000 |
| Subject: | Static vs. Instantiated Objects in PHP | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-234419@lists.php.net to get a copy of this message | ||
Greetings all,
Does anyone know how static objects work behind the scenes in PHP5? More specifically, is there a benefit to declaring an object and its methods as static vs the more traditional OO way of instantiating an object and then calling methods through the -> operator?
For example if I have:
class Example {
public static function doSomething() {
/* doing something here */
}
}
and
class Example {
private __construct() {
/* constructing here */
}
public function doSomething() {
/* doing something here */
}
}
Is it more/less/equally efficient for the engine and parser to do:
$result = Example::doSomething();
or
$example = new Example();
$result = $example->doSomething();
Thanks in advance,
Mark