You are here: Re: accessing vars from within classes « PHP Programming Language « IT news, forums, messages
Re: accessing vars from within classes

Posted by NC on 09/12/07 22:45

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

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация