php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #67225 Parser accepts Arrays as class-constants
Submitted: 2014-05-07 11:16 UTC Modified: 2015-03-29 09:47 UTC
From: sjon at hortensius dot net Assigned: bwoebi (profile)
Status: Closed Package: Compile Failure
PHP Version: 5.6.0beta2 OS: Archlinux
Private report: No CVE-ID: None
 [2014-05-07 11:16 UTC] sjon at hortensius dot net
Description:
------------
I have been going through 3v4l.org submitted scripts to find anomalies in 5.6.0-beta2; and I found http://3v4l.org/8Yl8V where the parser accepts an Array as class-constant; but when using that constant you still get a fatal error. This seems incorrect.

Here you see 5.6.0-beta2 incorrectly doesn't generate a fatal error: http://3v4l.org/8Yl8V
Here you see it does generate an error when using the const: http://3v4l.org/LG2EM

Test script:
---------------
<?php

interface exampleInterface
{
    const _TYPE = array(
        "name1" => "0",
        "name2" => "1",
        "name3" => "2"
    );

    public function x();
}
// Uncommenting this shows a Fatal error; but it should be show regardless
//class A implements exampleInterface { public function x(){var_dump(self::_TYPE);}}$a = new A;$a->x();

Expected result:
----------------
Fatal error: Arrays are not allowed in constants at run-time in /in/LG2EM on line 19

Process exited with code 255.

Actual result:
--------------
""

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2014-05-07 15:01 UTC] levim@php.net
-Assigned To: +Assigned To: bwoebi
 [2014-05-08 21:14 UTC] bwoebi@php.net
-Status: Assigned +Status: Suspended
 [2014-05-08 21:14 UTC] bwoebi@php.net
The error message clearly says _at run-time_. If you use it in compile-time only constructs, no problem.

I'll need to talk to other people later, but I'm relatively busy as of now.

Suspending for the next few weeks.
 [2014-05-09 08:42 UTC] sjon at hortensius dot net
Well; one part of the code accepting a syntax and another part rejecting will cause additional problems; such as demonstrated on http://3v4l.org/tMESk

<?php

interface exampleInterface
{
    const _TYPE = array(
        "name1" => "0",
        "name2" => "1",
        "name3" => "2"
    );

    public function x();
}

$r = new ReflectionClass('exampleInterface');

var_dump($r->getConstants());
 [2014-05-09 11:05 UTC] bwoebi@php.net
Yes, I know these issues.

Actually I neither see a reason why constant arrays are disallowed at all. It's something we need to discuss internally.

As said, I'll come back to this in a few weeks.
 [2015-03-29 09:47 UTC] bwoebi@php.net
-Status: Suspended +Status: Closed
 [2015-03-29 09:47 UTC] bwoebi@php.net
(actually fixed long ago for some RC of 5.6.0… no idea why that bug is still open)
 
PHP Copyright © 2001-2026 The PHP Group
All rights reserved.
Last updated: Tue Oct 06 13:00:01 2026 UTC