Bug #67225 [Com]: Parser accepts Arrays as class-constants

From: Date: Fri, 09 May 2014 08:42:54 +0000
Subject: Bug #67225 [Com]: Parser accepts Arrays as class-constants
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-185738@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=67225&edit=1

 ID:                 67225
 Comment by:         sjon at hortensius dot net
 Reported by:        sjon at hortensius dot net
 Summary:            Parser accepts Arrays as class-constants
 Status:             Suspended
 Type:               Bug
 Package:            Compile Failure
 Operating System:   Archlinux
 PHP Version:        5.6.0beta2
 Assigned To:        bwoebi
 Block user comment: N
 Private report:     N

 New Comment:

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());


Previous Comments:
------------------------------------------------------------------------
[2014-05-08 21:14:11] 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-07 11:16:09] 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:
--------------
""


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



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


Thread (5 messages)

« previous php.bugs (#185738) next »