Re: PHP5 Class problem
| From: | Richard Lynch | Date: | Fri, 28 Jan 2005 16:48:58 +0000 |
| Subject: | Re: PHP5 Class problem | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-207609@lists.php.net to get a copy of this message | ||
daniel@electroteque.org 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