Re: Boolean Parameter to 3 Options?
| From: | Philip Thompson | Date: | Wed, 29 Apr 2009 17:05:23 +0000 |
| Subject: | Re: Boolean Parameter to 3 Options? | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-292128@lists.php.net to get a copy of this message | ||
On Apr 29, 2009, at 11:42 AM, Matt Neimeyer wrote:
I have a function that currently takes a boolean value as a parameter. But now I want to expand it to 3 options... So if I have... function doFooBar($doFoo = false) { if($doFoo)Unless you're doing a strict comparison (===), it probably won't make a lot of difference. However, if you sent "true" to the function, I believe it will reach the last else condition. You may revisit all the locations you call it and update them appropriately. Those are my initial thoughts.... ~Philip{ echo "Did Foo"; }else{ echo "Did Bar"; }} Is it as "simple" as changing it like follows to avoid having to change existing code that won't use the new values. function doFooBar($doFoo = 0) { if($doFoo == 2){ echo "Did Baz"; }else if($doFoo == 1){ echo "Did Foo"; }else{ echo "Did Bar"; }} Something about that disturbs me. Perhaps because any time I think "Oh it will be as simple as..." it usually isn't. Thanks in advance! Matt