[thelist] PHP function args oddity
Lindsay Evans
lindsay at redsquare.com.au
Thu Nov 14 19:48:00 CST 2002
Named arguments aren't supported in PHP.
However, a quick Google for 'php "named arguments"' found the following
snippet from http://www.zend.com/zend/zengine/zengine-issue5.php
function hallo(name => $name = "not known", phone => $phone)
{
}
hallo(phone => "4711);
... and this one from
http://php.libero.it/manual/en/functions.arguments.php#8978
function foo($args)
{
print "named_arg1 : " . $args["named_arg1"] . "\n";
print "named_arg2 : " . $args["named_arg2"] . "\n";
}
foo(array("named_arg1" => "arg1_value", "named_arg2" => "arg2_value"));
--
Lindsay Evans.
Developer,
Red Square Productions.
[p] 8596.4000
[f] 8596.4001
[w] www.redsquare.com.au
> -----Original Message-----
> From: thelist-admin at lists.evolt.org
> [mailto:thelist-admin at lists.evolt.org]On Behalf Of Michael Mell
> Sent: Friday, November 15, 2002 12:33 PM
> To: thelist
> Subject: [thelist] PHP function args oddity
>
>
> 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