From: Operating system: PHP version: Irrelevant Package: Scripting Engine problem Bug Type: Feature/Change Request Bug description:Variables should also be accepted as default value for user-defined functions
Description: ------------ I can only use function test ($x = "Hello") {} I wish to be able to use also variables to define a default value of a function variable like function test ($x = $_SESSION["value"]) {} If the default-variable doesn't exist and the function isn't called with a parameter, PHP should output a notice that the default variable doesn't exist and assume that it would be NULL. Test script: --------------- <?php function test ($x = $GLOBALS["print"]) { var_dump($x); } // or maybe ($x = $print) ? $print = "Hello"; test("Bye"); // should output string(3) "Bye" test(); // should output string(5) "Hello" (the value of $GLOBALS["print"]) $print = "Hi"; test(); // should output string(2) "Hi" (the actual value of $GLOBALS["print"]) unset($print); test(); // should throw a notice "Undefined index: print" and output NULL ?> or for a method in a class <?php class x { public $print = "Hello" function test ($x = $this->print) { print $x; } } $x = new x; $x->test("Bye"); // should output "Bye" $x->test(); // should output "Hello" (the value of $x->print) ?> -- Edit bug report at https://bugs.php.net/bug.php?id=60544&edit=1 -- Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=60544&r=trysnapshot54 Try a snapshot (PHP 5.3): https://bugs.php.net/fix.php?id=60544&r=trysnapshot53 Try a snapshot (trunk): https://bugs.php.net/fix.php?id=60544&r=trysnapshottrunk Fixed in SVN: https://bugs.php.net/fix.php?id=60544&r=fixed Fixed in SVN and need be documented: https://bugs.php.net/fix.php?id=60544&r=needdocs Fixed in release: https://bugs.php.net/fix.php?id=60544&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=60544&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=60544&r=needscript Try newer version: https://bugs.php.net/fix.php?id=60544&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=60544&r=support Expected behavior: https://bugs.php.net/fix.php?id=60544&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=60544&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=60544&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=60544&r=globals PHP 4 support discontinued: https://bugs.php.net/fix.php?id=60544&r=php4 Daylight Savings: https://bugs.php.net/fix.php?id=60544&r=dst IIS Stability: https://bugs.php.net/fix.php?id=60544&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=60544&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=60544&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=60544&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=60544&r=mysqlcfg