php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #27523 Class constants don't work as class function parameter defaults
Submitted: 2004-03-07 22:29 UTC Modified: 2004-04-19 17:10 UTC
Votes:1
Avg. Score:3.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: random at sinfusion dot com Assigned:
Status: Wont fix Package: Documentation problem
PHP Version: 5.0.0b4 (beta4) OS: Windows 2000
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: random at sinfusion dot com
New email:
PHP Version: OS:

 

 [2004-03-07 22:29 UTC] random at sinfusion dot com
Description:
------------
Constants declared within a class are not recognized as such when used as function parameter default values for functions within the class.


Reproduce code:
---------------
class TestConstants
{

    const CONST_1 = 1;

    function test ($param = CONST_1)
    {
        echo $param;
    }
}

$test = new TestConstants();

$test->test();


Expected result:
----------------
1

Actual result:
--------------
Notice: Use of undefined constant CONST_1 - assumed 'CONST_1' in f:\dev\Web\pervercity.com\test\testconstants.class.php on line 8
CONST_1

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-03-08 11:28 UTC] wevegotafileonyou at hotmail dot com
You need to prepend the classname to the constant name (or use 'self') eg:

TestConstants::CONST_1
self::CONST_1

--
sleepeasy.
 [2004-03-08 12:09 UTC] random at sinfusion dot com
Okay, that sounds like a workaround, but you don't have to do that in the body of the class function.  Why should you have to do it differently here?
 [2004-03-09 08:45 UTC] sniper@php.net
Because you have to.

 [2004-03-09 12:07 UTC] random at sinfusion dot com
Then I would reclassify this as a documentation issue.
 [2004-04-19 17:09 UTC] nlopess@php.net
I wouldn't fix anything for this bug report, althought classes and OO need a huge rewrite because of PHP 5.
 [2004-04-19 17:10 UTC] nlopess@php.net
I wouldn't fix anything for this bug report, althought classes and OO need a huge rewrite because of PHP 5.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Oct 31 22:01:27 2024 UTC