|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2001-09-15 05:11 UTC] php at altemachtige dot reageerttochniet dot nl
<?php
$foo = 'foo';
function showvar( $bar = $foo )
{
//global $foo
//doesn't work either
echo $bar;
}
showvar();
showvar('bar');
?>
gives me a parse error on line 3:(
also:
<?php
$foo = 'foo';
function returnvar()
{
global $foo;
return $foo;
}
function whatisvar( $bar = returnvar() )
{
echo $bar;
}
?>
gives me this:
Parse error: parse error, expecting `')'' in c:/path/to/script/test.php on line 9
Should work, shouldn't it?
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Nov 01 22:00:02 2025 UTC |
no way, default values are evaluated at compile time and there is no $foo set at all as the program didn't start to run by that time what you want to do is something like function showvar ( $bar = NULL ) { if ( $bar === NULL ) { $bar = $GLOBALS['foo']; } echo $bar; }