Afficher un message
Vieux 12/09/2007, 20h53   #3
Shelly
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: accessing vars from within classes

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.googlegro ups.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
>



  Réponse avec citation
 
Page generated in 0,12158 seconds with 9 queries