[UPHPU] Sharing included data
Richard K Miller
richardkmiller at gmail.com
Wed Sep 6 17:35:26 MDT 2006
On Sep 6, 2006, at 1:18 PM, Jonathan Duncan wrote:
>
> On Wed, 6 Sep 2006, Jon Jensen wrote:
>
>>> However, as you can see, I have found it necessary to pass
>>> the object variable back into the object in order for the
>>> HEADER.INC.PHP file to be able to use the object and the data
>>> in it. This makes for a messy function call like this:
>>>
>>> $init->auth->userStatus
>>
>> You probably want to use "$this" instead. Since the include file
>> is being
>> inserted right in the middle of that class function, the code is
>> executed as
>> if it were right there in the function. Any local or member
>> variables will
>> be available to it. So you can do things like this in your include
>> file:
>>
>> var $foo = $this->auth->userStatus;
>> var $bar = $this->someFunction();
>>
>
> Yes, that works. Thanks. I have been too wrapped up in this code
> to recognize that I could use the $this for this particular usage.
> I appreciate your help.
>
I wonder if you might also like using the __autoload() function.
When you attempt to create a new object that hasn't been defined, it
automatically loads an include file of the same name:
http://www.php.net/manual/en/language.oop5.autoload.php
More information about the UPHPU
mailing list