Re: Calling A Class Variable as a Default for an Argument in a Function

From: Date: Tue, 06 Jun 2000 18:19:28 +0000
Subject: Re: Calling A Class Variable as a Default for an Argument in a Function
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-1138@lists.php.net to get a copy of this message
Jonathan Wright (DjNA) <mail@djna.fsnet.co.uk> wrote... > The first three arguments are fine, but I run into trouble with > the forth. It refuses to let me use it saying 'Parse Error in > ??? on line ???'. The manual doesn't seam to say much on the > matter, only talking about the first three cases. > > function start($one, > $two = "", > $three = "three", > $four = $this->four) > { return ($one, $two, $three, $four); } > http://www.php.net/manual/functions.arguments.php says: "The default value must be a constant expression, not (for example) a variable or class member." Try this: function start($one, $two="", $three ="three", $four=FALSE) { if(!$four) $four = [whatever non-constant thing you want]; ... return ($one, $two, $three, $four); }

« previous php.general (#1138) next »