[thelist] PHP function args oddity

Michael Mell mike at nthwave.net
Thu Nov 14 19:33:01 CST 2002


PHP4 isn't acting as I expect. Here's the situation:

<?
class MyClass {
	var $myVar1;
	var $myVar2;

	function MyClass ($myVar1, $myVar2='default') {
		$this->myVar1 = $myVar1;
		$this->myVar2 = $myVar2;
	}
}

$c1 = new MyClass('foo', $myVar2='bar');
// myVar2 == default ; INCORRECT, well, not what I expected

$c2 = new MyClass('foo', 'bar');
// myVar2 == bar ; correct, expected

?>

the unexpected behavior happens when I specify the name of the $myVar2
in the parameter string.
This is standard in other languages I've seen, right?




More information about the thelist mailing list