Re: [RFC] Square brackets shortcut

From: Date: Fri, 11 Jan 2008 06:15:26 +0000
Subject: Re: [RFC] Square brackets shortcut
References: 1 2 3  Groups: php.internals 
Request: Send a blank email to internals+get-34677@lists.php.net to get a copy of this message
> The [] array literal syntax is also used by Javascript, and there's even an > object literal syntax, {}, which is quite nice. Does that mean "Javascript > is classic Perl"? Yes, the first thing that comes to mind from this syntax is Perl. (1, 2, 3, 4, 5) ("dharma", "wilma", "greg", "mina") qw{ wilhelm yaztsee ben madonna } qw! wilhelm yaztsee ben madonna ! qw[ wilhelm yaztsee ben madonna ] Does this look familiar? Javascript is not classic Perl but the proposed way of assign array values is. > The [a:b, c:d] syntax would be more JSON-esque, while [a => b] syntax would > be more consistent with existing PHP. The latter, I think, would get > better traction with existing developers and be easier to understand (since > it uses the same separator character). If this is implemented, I would agree that sticking as close to the old syntax as possible is the best approach. I would go with the choice B except instead of square brackets use round brackets. $a = (1, 2, 3, 4, 5); $a = (1 => 'dharma', 2 => 'wilma'); This would be consistent with the old way of assigning array values and will probably least confuse both new and old developers. Tomi Kaistila PHP Developer

« previous php.internals (#34677) next »