From: David R. <da...@ro...> - 2009-09-02 19:15:07
|
> > $subscriber = new Subscriber(); > $profile = $subscriber->getValue("profile"); > $profile = new Profile($profile); // oops, now $profile is ambiguous > > By the way, I could just access $subscriber->profile rather than creating a > local variable for $profile, but I like making the class members protected > so I'm not tempted to set them directly and bypass any internal > functionality in the class. If I could make the members read-only, that > would work -- but PHP doesn't offer that, right? > For situations like this, I'll use the __get($name) magic function. http://us2.php.net/manual/en/language.oop5.overloading.php#language.oop5.overloading.members This allows you to set a member variable as Private, and yet still allow $object->readonly syntax and functionality. Additionally, you easily avoid having to worry about ambiguous variable names when you only really wanted to get a read-only copy of a member variable. Hope that helps. -Rovani |