Reply to Re: Getting and Setting and best practise

Your name:

Reply:


Posted by Steve on 04/20/07 21:25

"Vince Morgan" <vinhar@REMOVEoptusnet.com.au> wrote in message
news:46292dbe$0$5748$afc38c87@news.optusnet.com.au...
|
| "Steve" <no.one@example.com> wrote in message
| news:1P9Wh.1936$lq2.1174@newsfe04.lga...
| > | class C_Obj
| > | {
| > | private $Obj=array('h'=>10,'i'=>12);
| > |
| > | private function getVal($name)
| > | {
| > | return $this->Obj[$name];
| > | }
| > | function &__set($name, $val)
| > | {
| > | $name = $val;
| > | }
| > | function __get($name)
| > | {
| > | return self::getVal($name);
| > | }
| > | }
| >
| > yes, but here i must agree with the others. the reason why this works is
| > because you don't have the object's interface exposed. therefore, php
| > executes __set/__get. so in this case, the other posters are correct.
| >
| Wellllll, errrr, I just tried what is below, and it works on my machine.

i know it does vince. what i'm saying is that your object exposes NO public
interfaces *formally*...none that an end user could see. when you $obj->h, h
is added to the object. what __set/__get is SUPPOSED to be used for is
detecting helping the class detect this infusion/intrusion and throw an
error.

if you had $h as a public variable and then tried to say $obj->h = 'some
value', you'd never have __set be called by php.

give that a try and see what i mean.

[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

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