#27523 [Opn->Bgs]: Class constants don't work as class function parameter defaults

From: Date: Tue, 09 Mar 2004 13:45:50 +0000
Subject: #27523 [Opn->Bgs]: Class constants don't work as class function parameter defaults
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-56163@lists.php.net to get a copy of this message
 ID:               27523
 Updated by:       sniper@php.net
 Reported By:      random at sinfusion dot com
-Status:           Open
+Status:           Bogus
 Bug Type:         Zend Engine 2 problem
 Operating System: Windows 2000
 PHP Version:      5.0.0b4 (beta4)
 New Comment:

Because you have to.



Previous Comments:
------------------------------------------------------------------------

[2004-03-08 12:09:15] 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-08 11:28:42] 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-07 22:29:43] 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


------------------------------------------------------------------------


-- 
Edit this bug report at http://bugs.php.net/?id=27523&edit=1


Thread (4 messages)

« previous php.bugs (#56163) next »