Re: Re: named function arguments

From: Date: Fri, 24 Oct 2003 09:32:48 +0000
Subject: Re: Re: named function arguments
References: 1 2 3 4  Groups: php.internals 
Request: Send a blank email to internals+get-4955@lists.php.net to get a copy of this message
Sebastian Bergmann wrote:
Named parameters are commonly implemented using an associated array in PHP:
    <?php
    function foo($parameters) {}
    foo(
      array(
        'foo' => 'bar',
        'bar' => 'foo'
      )
    );
    ?>
So, how do you think that isn't known to the original poster as he even explicitely states that he wants to remove the need for array()?
I was also thinking of proposing named parameters, i.e. basically removing the need for array() in foo(array('style' => 'hot', 'size' => 42)); but I guess that'll be even more controversial
Also, notice that there is quite a disctinction between keyword/named parameters and passing an associated array to the function - in the former case, several optimizations could be implemented at "compile time" (what is the correct term for this in the PHP model?); in your (the common) way of faking named parameters, you rely on a) hash lookups at execution time (for _every_ call) and b) on manually dealing with default values.

« previous php.internals (#4955) next »