argument order

Not for 'how-to' coding questions but PHP theory instead, this forum is here for those of us who wish to learn about design aspects of programming with PHP.

Moderator: General Moderators

User avatar
kyberfabrikken
Forum Commoner
Posts: 84
Joined: Tue Jul 20, 2004 10:27 am

Post by kyberfabrikken »

superdezign wrote:
astions wrote:

Code: Select all

function some_function($a = array())
{

}
I could have sworn I've seen this done before...
Yeah. That's perfectly valid syntax in PHP.
User avatar
stereofrog
Forum Contributor
Posts: 386
Joined: Mon Dec 04, 2006 6:10 am

Post by stereofrog »

Indeed. The language parser allows only "static_scalar"s at this point

http://lxr.php.net/source/ZendEngine2/z ... rser.y#430

but the definition of "static_scalar" quite surprisingly includes arrays as well

http://lxr.php.net/source/ZendEngine2/z ... rser.y#700

"static_scalar" arrays recursively consist of "static scalar"s, so something like this would be also possible (although hardly useful)

Code: Select all

function foo(
	$a = array('bar' => array('baz'))
) {
Post Reply