3cho

Friday, January 12, 2007

Weird PHP Stuff

<?php
$a = "first arg";
$b = "second arg";
$c = "3";
$d = "4";
$e = "x";

take2($a, $b, $c, $d, $e);

function take2($one, $two) {
echo "\$one is '$one'";
echo "\$two is '$two'";
}
?>

Even though the number of arguments in the call to take2 is wrong, PHP executes this without a peep. No problem. And the output is:
$one is 'first arg'
$two is 'second arg'
If you try to execute with too few arguments, like this:

take2($a);

the code still executes, but you get a warning like this:
Warning:  Missing argument 2 for take2()

and the output is:

$one is 'first arg'
$two is ''

Weird stuff. I did not know any of this!

Tested with Apache/1.3.26 (Unix) PHP/4.2.1
But I'm seeing this effect in PHP5 as well.

0 Comments:

Post a Comment

<< Home