Re: global class instance

From: Date: Sat, 01 Jul 2006 10:50:47 +0000
Subject: Re: global class instance
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-239052@lists.php.net to get a copy of this message
On 7/1/06, chris smith <dmagick@gmail.com> wrote:
On 7/1/06, sempsteen <sempsteen@gmail.com> wrote: hi all, i wonder if there is a way of creating an instance of a class and reach it direcly from any scope in PHP4. basically what i want is: class a { function print() {
      echo 'sth';
} } $a = new a(); and use this "a" instance from anywhere ex, in a function that is a method of another class. class b { function print() {
      $a->print();
} } i don't want to: - declare global $foo, - use pre-defined $GLOBALS variable, - or use a::print Then you're out of luck.
Actually you could pass it in: function print(&$a) { $a->print(); } but thats going to cause you lots of pain if you call it a lot (ie you forget to pass it in everywhere). -- Postgresql & php tutorials http://www.designmagick.com/

« previous php.general (#239052) next »