On PHP short array syntax

Submitted by nk on Tue, 2008-06-03 18:35.

There is a heated debate on PHP internals list -- this in itself is not news, the list should be called "php heated debate list" btw. -- about short array syntax. What I will write here is probably know to the Drupal readers -- less known to the PHP internals list, I guess. So, I am the form API maintainer of Drupal, which probably is the most complex array based API in existence. I support the $b = ['foo' => 'orange', 'bar' => 'apple', 'baz' => 'lemon']; wholeheartedly. I less like $b = ['foo': 'orange', 'bar': 'apple', 'baz': 'lemon']; but I guess we could be friends with this one too :) Also, could we get named parameters and closures? Please?

Submitted by kourge@drupal.org on Wed, 2008-06-04 02:46.

My immediate reaction upon seeing this is that the double arrow syntax is more traditionally like PHP and Ruby, while the colon syntax is more like Python and JavaScript.

PHP: $b = array('foo' => 'orange', 'bar' => 'apple', 'baz' => 'lemon') # Makes an associated array
Ruby: b = {'foo' => 'orange', 'bar' => 'apple', 'baz' => 'lemon'} # Makes a hash
Python: b = {'foo': 'orange', 'bar': 'apple', 'baz': 'lemon'} # Makes a dictionary
JavaScript: var b = {'foo': 'orange', 'bar': 'apple', 'baz': 'lemon'}; // Makes an object

Funny how the four languages all have different names for this.

User login

Log in using OpenID

No user registration here. Use your DrupalID from drupal.org, for eg. chx@drupal.org