From: Richard L. <ce...@l-...> - 2009-09-09 18:11:37
|
You could write a __get() and no __set but some other "secret" way to change a value, and achieve something like a read-only member var. As far as $profile goes, I'd suggest: $subscriber = new Subscriber(); $subscriber_profile = $subscriber->getValue('profile'); $profile = new Profile($subscriber_profile); is probably the way to go. You most likely won't be using $subscriber_profile for long... Another option is to create a method on Subscriber that returns a Profile object, and don't ever mess directly with the value at all. On Wed, September 2, 2009 11:33 am, Arlo Leach wrote: >> It'd be really confusing code with those similar names. > >> Yes, it is kind of crazy: you're deliberately obfuscating your own >> code. >> Using the same name two different ways is shooting yourself in the >> foot. I'm a lousy typist myself, but it would never occur to me to >> try something like this. > > All right, thanks for the sanity check. I could to something like > $objProfile or $obj_profile, but I've always stayed away from that > Hungarian > notation kind of approach. > > The most common situation I've run into is that one variable name > describes > both an object and a member in a related class. For example, I have > subscribers and some subscribers have profiles. Here's a > super-simplified > example: > > $subscriber = new Subscriber(); > $profile = $subscriber->getValue("profile"); > $profile = new Profile($profile); // oops, now $profile is ambiguous > > Since the profile member in the Subscriber class is a pointer to a > separate > Profile record, I guess most people would call that $profile_id. > That's > almost like Hungarian notation to me and I've never had the need to do > that > before. But now that I'm using objects a lot, my namespace has to > accommodate one more type of data than before, so something has to > give. > > 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? > > Cheers, > -Arlo > > _______________________________ > > Arlo Leach > 773.769.6106 > http://arlomedia.com > > > > > ------------------------------------------------------------------------------ > Let Crystal Reports handle the reporting - Free Crystal Reports 2008 > 30-Day > trial. Simplify your report design, integration and deployment - and > focus on > what you do best, core application coding. Discover what's new with > Crystal Reports now. http://p.sf.net/sfu/bobj-july > _______________________________________________ > chiPHPug-discuss mailing list > chi...@li... > https://lists.sourceforge.net/lists/listinfo/chiphpug-discuss > -- Some people ask for gifts here. I just want you to buy an Indie CD for yourself: http://cdbaby.com/search/from/lynch |