|
Posted by Shelly on 09/12/07 18:53
I have a simple question, You are using classes because you want to be OO
rather than procedural. Why, then, would you expect what you did to work.
Instead, OtherClass should have accessor and mutator methods. It would bebe
executed as $otherClassInstance.setOtherVar($myVar) where
$otherClassInstance is and instance of OtherClass.
So, in summary, if you are procedual then stay procedural and if you are OO
then stay OO.
"PaowZ" <gpaowz@gmail.com> wrote in message
news:1189616607.313148.113350@w3g2000hsg.googlegroups.com...
> Hello there!
>
> I'd like to make some declared vars available to classes, such as:
>
> <? //main environment
> $myVar = new MyClass(); //the var I want to be available to OtherClass
> ...
> ...
> class OtherClass{
> private $otherVar = $myVar; //seems to not work
> ..
> }
> ?>
>
> ..and I wish to initialize $otherVar 'as is', I mean, without having
> to pass arg through __construct(). The way I tried above doesnt seem
> to work, unlike it would be in a function..
>
> any idea ??
>
> thanks a lot :)
>
[Back to original message]
|