RE: [PHP] global class instance

2006-07-07 Thread Richard Lynch
On Wed, July 5, 2006 3:32 pm, KermodeBear wrote: i don't want to: - or use a::print $myFoo = Singleton::getFoo(); What's wrong in this picture? :-) As far as I can tell, the original poster shouldn't be using PHP, since he wants the language to have some kind of implicit $this -- Like

Re: [PHP] global class instance

2006-07-05 Thread Eric Butera
On 7/1/06, sempsteen [EMAIL PROTECTED] 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

RE: [PHP] global class instance

2006-07-05 Thread KermodeBear
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: i don't want to: - declare global $foo, - use pre-defined $GLOBALS variable, - or use a::print thanks. Static is your friend.

Re: [PHP] global class instance

2006-07-03 Thread Richard Lynch
On Sat, July 1, 2006 4:56 am, sempsteen wrote: 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

Re: [PHP] global class instance

2006-07-02 Thread John Wells
On 7/1/06, sempsteen [EMAIL PROTECTED] 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: ... i don't want to: - declare global $foo, - use pre-defined $GLOBALS variable, - or use a::print

Re: [PHP] global class instance

2006-07-02 Thread Chris
sempsteen wrote: yes i'm calling a lot. actually i have a class that handles mysql queries named database. what i want was call a database method from a method of another function. class function ...$database-execute_query(... Always CC the list. What's wrong with this being a

Re: [PHP] global class instance

2006-07-01 Thread chris smith
On 7/1/06, sempsteen [EMAIL PROTECTED] 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

Re: [PHP] global class instance

2006-07-01 Thread chris smith
On 7/1/06, chris smith [EMAIL PROTECTED] wrote: On 7/1/06, sempsteen [EMAIL PROTECTED] 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';

Re: [PHP] global class instance

2006-07-01 Thread Larry Garfield
It sounds like your only other option is a singleton, which works only if you're comfortable having only one instance of a, ever. The following code also only works in PHP 5. class A { static obj; static instance() { if (! self::obj instanceof A) { self::obj = new A(); }

Re: [PHP] global class instance

2006-07-01 Thread Larry Garfield
You can simulate singletons in PHP 4 as well. But you've just eliminated every option for accessing a non-local object inside a function. You've got 4 options. Pick one, but I'm fairly certain there is no magical 5th. :-) On Saturday 01 July 2006 13:02, sempsteen wrote: Thanks Larry but i'm