Re: Function parameter passed by reference with default value to null

From: Date: Mon, 06 Jul 2009 09:40:13 +0000
Subject: Re: Function parameter passed by reference with default value to null
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-294934@lists.php.net to get a copy of this message
2009/7/6 Lupus Michaelis <mickael+php@lupusmic.org>: >  Hi, > >  I would like to know if I am alone to be shoked by this : > > == 8< == > function foo(& $bar = null) > { > } > > foo() ; // runs > foo(null) ; // raise an error > == >8 == > >  Why the default value to null for a reference is allowed ? Is it a bug, a > feature ? You appear to be using the definition of null that comes from the world of C. A null in PHP is not the same as a null in C - it's a real value (of type null), not the absence of a value. So what you're doing is the equivalent of passing a literal value, something you can't do when the function is expecting a reference. See the manual for more info on the null type: http://php.net/null -Stuart -- http://stut.net/

« previous php.general (#294934) next »