Forum Moderators: coopster

Message Too Old, No Replies

how super are superglobals

can't be used as the default value in a function definition?

         

ergophobe

7:48 pm on Dec 9, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Really basic question here. Just when do superglobals become available? In other words

This works fine:


function func($var1, $var2, $action="") {
$action=$_SERVER['PHP_SELF'];
...
}

This gives "Parse error: parse error, unexpected T_VARIABLE in doc.php on line 5" :


function nav_form($prev, $next, $action=$_SERVER['PHP_SELF']) {
...
}

Tom

coopster

8:09 pm on Dec 9, 2003 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Can't do that, ergophobe. The default value must be a constant expression, not (for example) a variable, a class member or a function call. See Default argument values [php.net] in the functions reference pages.

ergophobe

8:28 pm on Dec 9, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Check! Same as class members and all.

I guess I've just never tried to do it before.

Tom