php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #27749 const's in classes are no longer recognized, define works again in classes
Submitted: 2004-03-29 06:01 UTC Modified: 2004-03-29 09:43 UTC
From: kris dot hofmans at pandora dot be Assigned:
Status: Not a bug Package: *General Issues
PHP Version: 5.0.0RC1 OS: Linux 2.6
Private report: No CVE-ID: None
 [2004-03-29 06:01 UTC] kris dot hofmans at pandora dot be
Description:
------------
I have been using the const in classes since the change from define, this change seems to be reverted in RC1?

Since it doesn't recognize the constants, using define in the constructor it works again, but I hope this is not the final behaviour.

Reproduce code:
---------------
class bleh {

    const MYCONST = "hello world";

    public function printMyConst(){
        // doesn't work in RC1
        print(MYCONST);

    }

}

adding:

public function __construct(){

    define("MYCONST", "hello world");

}

fixes it.

Expected result:
----------------
I hope const will be the default behaviour for php5, not reverting to the deprecated php4 define method

Actual result:
--------------
Use of undefined constant ...

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-03-29 09:43 UTC] amt@php.net
This is a new change. You now need to do self::MYCONST 
to indicate you want the class's MYCONST.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Mon Jul 14 03:01:31 2025 UTC