php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #43213 Unable to define distinct class constants
Submitted: 2007-11-07 16:09 UTC Modified: 2007-11-11 14:58 UTC
From: uli dot staerk at globalways dot net Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: 5.2.4 OS:
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: uli dot staerk at globalways dot net
New email:
PHP Version: OS:

 

 [2007-11-07 16:09 UTC] uli dot staerk at globalways dot net
Description:
------------
You can define class constants like:
class foo {
    const bar = "baz";
}

But if the constant-name is array, it does not work.

Reproduce code:
---------------
<?php

class Test {
	const Array = "array";
}

?>

Expected result:
----------------
It should work ;)

Actual result:
--------------
Parse error: syntax error, unexpected T_ARRAY, expecting T_STRING in test.php on line 4

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-11-07 16:22 UTC] carsten_sttgt at gmx dot de
You can found the answer here:
http://de.php.net/manual/en/reserved.php

| You cannot use any of the following words (PHP Keywords)
| as constants, class names, function or method names.
("array" is one of them)

Regards,
Carsten
 [2007-11-07 17:56 UTC] uli dot staerk at globalways dot net
So there is no difference beween class constants and (common script) constants?
 [2007-11-11 14:58 UTC] derick@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Sat Jul 12 05:01:33 2025 UTC