RE : [PHP-DEV] Re: Syntactic improvement to array

From: Date: Tue, 06 Feb 2007 14:17:14 +0000
Subject: RE : [PHP-DEV] Re: Syntactic improvement to array
References: 1  Groups: php.internals 
Request: Send a blank email to internals+get-27852@lists.php.net to get a copy of this message
> From: Richard Lynch > > How many newbies will be trying: > array[1, 2, 3]; > and left scratching their heads when it doesn't work? Yes, even if I am in favor of the [] syntax, it is a good argument: 'array[ 1, 2, 3]' can become a very common error, and not especially among newbies! Maybe I am wrong, but would it be possible to accept all these syntaxes : array(1, 2, 3) (RHS only) [ 1, 2, 3 ] (RHS=array / LHS=list, I especially like: '$x = [ $a, $b ] = f()' :) list($a, $b) (LHS only) array[1, 2, 3] (RHS only) For this purpose, we could say that the [] notation is optionally preceded by 'array'. Another idea if you want to make it easier to understand for newbies: make array() and list() synonyms, so that array() behaves as list() when LHS, and list() behaves as array() when RHS. IMHO, it would become simpler to explain. If we implement both, we can even suppport 'list[ 1, 2, 3 ]'. How can we be more permissive? Regards Francois

« previous php.internals (#27852) next »