Reply to Re: accessing vars from within classes

Your name:

Reply:


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]


Удаленная работа для программистов  •  Как заработать на 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

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