...

View Full Version : Internal Default Method Parameters



zro@rtv
12-21-2006, 06:20 AM
quick question, sry if its stupid.

I can't do this right?


class Myclass{

var $bob;

function myFunc($foo = $this->bob){
echo $foo;
}

}


so im doing this:


class Myclass{

var $bob;

function myFunc($foo = 'unset'){
if ($foo == 'unset')
$foo = $this->bob;

echo $foo;
}

}
]

Is this appropriate? or am i crazy, or stupid, or thinking about this all wrong?
THANKS IN ADVANCE!

GJay
12-21-2006, 07:49 AM
your assumptions are correct, the more common solution is to use 'null' (no quotes...see below) as the default, rather than strings that could be confusing.
e.g.


function myFunc($foo=null) {
if($foo==null) {
$foo=$this->bob
}

zro@rtv
12-21-2006, 08:13 AM
o yes, of course!
duh. what was i thinking?

Thanks so much fr the kick in the pants.
I swear sometimes i just stare at this shtuff 2 long and i lose my mind a bit.

thanks again!



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum