|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #13315 problem with function definitions
Submitted: 2001-09-15 05:11 UTC Modified: 2001-09-15 07:27 UTC
From: php at altemachtige dot reageerttochniet dot nl Assigned:
Status: Not a bug Package: *General Issues
PHP Version: 4.0.4pl1 OS: WIN98/APACHE1.3.19
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
Solve the problem:
42 - 12 = ?
Subscribe to this entry?

 [2001-09-15 05:11 UTC] php at altemachtige dot reageerttochniet dot nl
    $foo = 'foo';
    function showvar( $bar = $foo )
        //global $foo
        //doesn't work either
        echo $bar;

gives me a parse error on line 3:(


    $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?


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2001-09-15 05:28 UTC]
Shouldn't. Default values must be constant expressions.

Not a bug, bogusified.

- Markus
 [2001-09-15 05:43 UTC] php at altemachtige dot reageerttochniet dot nl
why is that? I really need this:(
Will a later version of php support constructions like this?
 [2001-09-15 07:27 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;
PHP Copyright © 2001-2022 The PHP Group
All rights reserved.
Last updated: Tue Jul 05 10:05:45 2022 UTC