NYCPHP Meetup

NYPHP.org

[nycphp-talk] Object Methods and Properties

Daniel Convissor danielc at analysisandsolutions.com
Thu Jul 29 13:01:55 EDT 2004


Joe:

On Thu, Jul 29, 2004 at 12:29:49PM -0400, Joe Crawford wrote:
> 	function setPart($part, $val, $append=FALSE) {
> 		if (in_array($part, get_class_vars(get_class($this)))) {
> 			if(($part) && ($val)) {
> 				if ($append) $this->{'_' . $part} .= $val;
> 				else $this->{'_' .$part} = $val;
> 			}

First off, aren't you mixing up your variable variable substitution?  
In some places you're using $part and in others you're using
'_' . $part.  They are not the same thing.

You really should be calling the method with the REAL property name.  
So, if the property is called "_foo", pass "_foo" to the $part 
parameter.  That's far clearer and faster than passing "foo" to $part 
and then tacking on the '_' repeatedly.

Let alone, why are you calling them "parts"?  They are "properties."

Now, all that aside, as someone mentioned the other day, your 
class_vars check is overly complex for no reason.  Just do an isset() 
check.

    if (isset($this->$part)) {
    }

OR, if you insist on continuing the ambiguous automatic underscore 
prefixing:

    if (isset($this->{'_' . $part})) {
    }

You mistakenly replied to them that you don't want to set unset 
properties.  That's what this check prevents.

--Dan

PS:  When composing replies in the future, PLEASE be so kind as to 
delete the vast majority of the quoted content from prior postings 
rather than being lazy and just leaving there.

-- 
 T H E   A N A L Y S I S   A N D   S O L U T I O N S   C O M P A N Y
            data intensive web and database programming
                http://www.AnalysisAndSolutions.com/
 4015 7th Ave #4, Brooklyn NY 11232  v: 718-854-0335 f: 718-854-0409



More information about the talk mailing list