Azu Posted March 7, 2007 Share Posted March 7, 2007 function dumbyfunction($test_var="lol"){die($test_var);} Works But function dumbyfunction($test_var="getenv('REMOTE_ADDR')"){die($test_var);} function dumbyfunction($test_var=getenv('REMOTE_ADDR')){die($test_var);} function dumbyfunction($test_var="$GLOBALS[MyIp]"){die($test_var);} function dumbyfunction($test_var='$GLOBALS[MyIp]'){die($test_var);} function dumbyfunction($test_var='getenv('REMOTE_ADDR')'){die($test_var);} all crash and burn. Please tell me why this happens and how I can fix it. Link to comment https://forums.phpfreaks.com/topic/41620-solved-declaring-a-function/ Share on other sites More sharing options...
trq Posted March 7, 2007 Share Posted March 7, 2007 As stated in the manual. The default value must be a constant expression, not (for example) a variable, a class member or a function call. Link to comment https://forums.phpfreaks.com/topic/41620-solved-declaring-a-function/#findComment-201652 Share on other sites More sharing options...
obsidian Posted March 7, 2007 Share Posted March 7, 2007 As stated in the manual. The default value must be a constant expression, not (for example) a variable, a class member or a function call. In other words, you need to default your value to NULL or something else recognizable, and if the default value comes through, assign the function call within your declared function: <?php function dummyfunction($test_var = '') { if (empty($test_var)) $test_var = getenv('REMOTE_ADDR'); die($test_var); } ?> Link to comment https://forums.phpfreaks.com/topic/41620-solved-declaring-a-function/#findComment-201678 Share on other sites More sharing options...
Azu Posted March 7, 2007 Author Share Posted March 7, 2007 Okay thanks, it is working now and no errors =D Link to comment https://forums.phpfreaks.com/topic/41620-solved-declaring-a-function/#findComment-201730 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.