Page MenuHomePhabricator

Add a linter rule for arrays not being allowed as class constants
Open, WishlistPublic

Description

The following code should raise a linter error, but currently does not:

<?php

class MyClass {
  const SOME_CONSTANT = array(1, 2, 3);
}

Trying to execute this code produces a fatal error:

PHP Fatal error:  Arrays are not allowed in class constants in /home/joshua/workspace/github.com/phacility/libphutil/test.php on line 4

Event Timeline

joshuaspence raised the priority of this task from to Wishlist.
joshuaspence updated the task description. (Show Details)
joshuaspence added a project: Lint.
joshuaspence added a subscriber: joshuaspence.

Actually, this is perfectly fine in PHP 5.6 I believe.

Yeah, in 5.6 this works.

richard @dev[~]
-> php -v
PHP 5.6.2-1 (cli) (built: Oct 17 2014 17:15:37) 
Copyright (c) 1997-2014 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2014 Zend Technologies
    with Zend OPcache v7.0.4-dev, Copyright (c) 1999-2014, by Zend Technologies
    with Xdebug v2.2.5, Copyright (c) 2002-2014, by Derick Rethans

richard @dev[~]
-> php -r 'class Test { const MY = [1, 2, 3]; } var_dump(Test::MY);'
array(3) {
  [0] =>
  int(1)
  [1] =>
  int(2)
  [2] =>
  int(3)
}