RE: [PHP] Using Static Class Variables to Access Globally
| From: | Richard Lynch | Date: | Wed, 24 Sep 2008 01:12:19 +0000 |
| Subject: | RE: [PHP] Using Static Class Variables to Access Globally | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-280812@lists.php.net to get a copy of this message | ||
> -----Original Message-----
> From: Ryan Panning [mailto:rpanning@gmail.com]
> Sent: Tuesday, September 23, 2008 8:03 PM
> To: php-general@lists.php.net
> Subject: [PHP] Using Static Class Variables to Access Globally
>
> 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.
I can't think of any particular reason to not do this.
_______________________________________________________
The information in this email or in any file attached
hereto is intended only for the personal and confiden-
tial use of the individual or entity to which it is
addressed and may contain information that is propri-
etary and confidential. If you are not the intended
recipient of this message you are hereby notified that
any review, dissemination, distribution or copying of
this message is strictly prohibited. This communica-
tion is for information purposes only and should not
be regarded as an offer to sell or as a solicitation
of an offer to buy any financial product. Email trans-
mission cannot be guaranteed to be secure or error-
free. P6070214