Using Static Class Variables to Access Globally

From: Date: Wed, 24 Sep 2008 01:03:28 +0000
Subject: Using Static Class Variables to Access Globally
Groups: php.general 
Request: Send a blank email to php-general+get-280811@lists.php.net to get a copy of this message
The typical way to access a variable or instance from inside a function/method is to either declare it a global variable or pass it as a argument. Is there any reason why someone shouldn't use static class variables to do this? Ex: <?php class Foo { public static $bar_instance; } class Bar { public function do_something() {} } Foo::$bar_instance = new Bar; function foo_bar() { Foo::$bar_instance->do_something(); } foo_bar(); ?> Crude example but imagine this on a larger scale. I'm thinking there may be some kind of php optimization that this would hamper or something to that effect.

« previous php.general (#280811) next »