From: Arlo L. <ar...@ar...> - 2009-09-02 17:00:29
|
> 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 |