Afficher un message
Vieux 13/09/2007, 00h45   #4
NC
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: accessing vars from within classes

On Sep 12, 10:03 am, PaowZ <gpa...@gmail.com> wrote:
>
> $myVar = new MyClass(); //the var I want to be available to OtherClass
> ...
> ...
> class OtherClass{
> private $otherVar = $myVar; //seems to not work
> ..}


But of course. The scope of $myVar is lies outside OtherClass, so
$myVar is meaningless in the context of OtherClass.

> ..and I wish to initialize $otherVar 'as is', I mean,
> without having to pass arg through __construct().


And I wish to build a perpetual motion machine. Alas, the world does
not work that way...

> The way I tried above doesnt seem to work, unlike it would
> be in a function..


It wouldn't work in a function either, unless you declare $myVar as
global.

> any idea ??


Don't let your wishes control you; control your wishes instead.

Cheers,
NC

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