On 13.04.2010 01:30, Pierre Joye wrote:
> On Tue, Apr 13, 2010 at 1:28 AM, Stanislav Malyshev <stas@zend.com> wrote:
>
>> I think that's the idea in general, now how it looks like - be it 'opt1'
>> =>
>> 'no-foo' or opt1: 'no-foo' - that's the decision we need to take.
>> I
>> personally still don't have the favorite, but in every case we still have
>> the full params list, otherwise the whole story is kind of useless - we can
>> pass arrays as arrays now.
>
> I'd to go with opt1: 'value', I really don't the idea of having to use
> quotes for the name of the argument.
Same here, although quoted means that we could potentially use dynamic
values (pending approval from parser gurus). I don't care for it, but I
know people will ask..
As for the passing arrays, in some cases, I think if we introduce named
parameters we might as well take the occasion to implement the "rest"
operator. In actionscript3 you can do the following (written in php):
function foo($a, $b, ... $stuff) {
print_r($stuff);
}
foo(1, 2, foo: FOO, bar: BAR);
// array('foo' => 'FOO', 'bar' => 'BAR')
Now you only get "args that weren't defined but still passed" in this
magic array. In AS3 you don't have named params so it's a bit of a
func_get_args() + array_shift() equivalent, but here it would allow you
to pass arbitrary values as an array without having to use the whole
array syntax, which while we're at it would make the
array-shorthand-please camp happy too I believe.
Another use for that operator, as I had requested a few years ago, would
be to allow extending/implementing a function with potentially more args
than the minimal interface requires, without hacking it with
func_get_args(), i.e. this:
interface foo {
function bar($a);
}
class fooimpl implements foo {
function bar($a, $b) {
}
// Fatal error: Declaration of fooimpl::bar() must be compatible with
that of foo::bar()
While using rest arg without/after a var name would allow extending the
arg signature:
interface foo {
function bar($a ...);
}
class fooimpl implements foo {
function bar($a, $b) {
}
// Happily declared
Cheers,
Jordi
Attachment: [application/pgp-signature] OpenPGP digital signature signature.asc