RE: [PHP] php 4.0.2 and args in a function

From: Date: Fri, 01 Sep 2000 18:56:44 +0000
Subject: RE: [PHP] php 4.0.2 and args in a function
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-14858@lists.php.net to get a copy of this message
> > I noticed some 'new behavior' with the release of php 4.0.2 and I'm not > sure if it's intended behavior or if it's just my coding style. Here's a > small sample script I wrote to demo the problem: Dont think it was new.. I think maybe it was a bug in 4.0.0 but someone might correct me on that. > 00 <? > 01 function smoosh($var1, $var2) { > 02 return $var1 . $var2; > 03 } > 04 ?> > 05 <HTML> > 06 <BODY> > 07 <? > 09 $onevar = smoosh("string1a","string2a"); > 10 print("<P>".$onevar); > 11 $twovar = smoosh("string1b"); > 12 print("<P>".$twovar); > 13 ?> > 14 </BODY> > 15 </HTML> > > And the output: > > 00 string1astring2a > 01 Warning: Missing argument 2 for smoosh() in > /home/httpd/html/testpage.html on line 2 > 03 > 04 string1b this is the way it should be done: 00 <? 01 function smoosh($var1, $var2 = "") { /*Give $var2 a defauilt value making it optional */ 02 return $var1 . $var2; 03 } 04 ?> 05 <HTML> 06 <BODY> 07 <? 09 $onevar = smoosh("string1a","string2a"); 10 print("<P>".$onevar); 11 $twovar = smoosh("string1b"); 12 print("<P>".$twovar); 13 ?> 14 </BODY> 15 </HTML> James

« previous php.general (#14858) next »