Re: PHP5 Class problem

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



daniel@xxxxxxxxxxxxxxxx wrote:
>
>>
>> 1. you are calling the method on a object
>> (i.e. not as a static call like SessionHandler::getOrgSession())
>>
>> 2. the function (method) you are calling is _NOT_ defined as static.
>>
>> in your case you have defined all your methods as static.... so the
>> engine will not make $this available even if you call the
>> method/function on an instantiated object.
>>
>> solution - remove 'static' from the function definitions that you wish
>> to use $this in.
>>
>
>
> how odd, i have assumed having a class static you could still throw around
> variables inside it, or its only meant to stay in the one static method so
> executing it like

As I understand it...

It's not that you can't use any variables at all -- It's that "$this"
doesn't make any sense in that context.

"$this" refers to the particular instance of the object you have created
with "new XYZ"

$xyz = new XYZ();
$xyz->bar();
When bar refers to "$this" it means the same as the "$xyz" instance.

If you are calling a static method XYZ::foo() then, really, there *IS* no
object inside of foo() to be called "$this" -- You didn't create an
instance of XYZ, so there is no instance to be named "$this" -- There is
only the class definition and the method.

It's an object that's not there -- more like the idea of an object without
having an actual concrete object to hang on to.

Hope that helps make sense of it all.

Hell, hope that's actually correct! :-^

-- 
Like Music?
http://l-i-e.com/artists.htm

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux