|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2014-09-22 14:21 UTC] piotrekrogowski at gmail dot com
[2014-09-29 00:24 UTC] bwoebi@php.net
-Status: Open
+Status: Wont fix
[2014-09-29 00:24 UTC] bwoebi@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Tue Oct 28 19:00:01 2025 UTC |
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) ?>