Bug #12856: dynamic default function parameter not possible

From: Date: Mon, 20 Aug 2001 10:36:13 +0000
Subject: Bug #12856: dynamic default function parameter not possible
Groups: php.dev 
Request: Send a blank email to php-dev+get-63817@lists.php.net to get a copy of this message
From: marcus.boerger@post.rwth-aachen.de Operating system: PHP version: 4.0.6 PHP Bug Type: Feature/Change Request Bug description: dynamic default function parameter not possible Hi all, Why is it not possible to have dynamic default function parameters? This would give the possibility to execute any code snippet when the default value will be used in a function code. At current time you can only define function f( $v=<statis_val>) { return $v; } return f(); what would result in: <static_val> BUT sometimes there must be a dynamic part. For example when dealing with times. Consider the following: function t( $v=null) { if ($v===null) $v=time(); return date( "r", $v); } return t(); what would return the current time formatted. With dynamic defaults this would enable the following: function t($v=time()) { return date( "r", $v); } return t(); Additionally that *should* be used to give access to global variables: $d = time(); function t($v=$d) { return date( "r", $v); } return t(); // formatted time of script start..or given time Another good idea would be to execute the variables from within context: $d = 1; function t($v=$d) { return $v; } function t2() { $d=2; return t(); } function t3($v=$GLOBALS['d']) { return $v; } return t(); // --> 1 return t2(); // --> 2 return t3(); // --> 1 greetings marcus -- Edit bug report at: http://bugs.php.net/?id=12856&edit=1

« previous php.dev (#63817) next »