php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #69913 arrays are allowed in 'const' but not 'define'
Submitted: 2015-06-23 16:04 UTC Modified: 2015-06-23 16:06 UTC
From: gordon dot mcvey at ntlworld dot com Assigned: nikic (profile)
Status: Closed Package: Scripting Engine problem
PHP Version: 5.6.10 OS: OSX 10.10.3
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: gordon dot mcvey at ntlworld dot com
New email:
PHP Version: OS:

 

 [2015-06-23 16:04 UTC] gordon dot mcvey at ntlworld dot com
Description:
------------
./php -v
PHP 5.6.9 (cli) (built: May 15 2015 13:05:42) 
Copyright (c) 1997-2015 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2015 Zend Technologies
    with Zend OPcache v7.0.4-dev, Copyright (c) 1999-2015, by Zend Technologies
    with Xdebug v2.2.5, Copyright (c) 2002-2014, by Derick Rethans

You can define an array in PHP 5.6 on a constant if you use const.  However, you can't if you use define.  This seems like inconsistent behaviour.  



Test script:
---------------
<?php
const A = [1,2,3];
var_dump (A);
define ("B", [4,5,6]);
var_dump (B);


Expected result:
----------------
array(3) {
  [0] =>
  int(1)
  [1] =>
  int(2)
  [2] =>
  int(3)
}
array(3) {
  [0] =>
  int(4)
  [1] =>
  int(5)
  [2] =>
  int(6)
}


Actual result:
--------------
array(3) {
  [0] =>
  int(1)
  [1] =>
  int(2)
  [2] =>
  int(3)
}
PHP Warning:  Constants may only evaluate to scalar values in php shell code on line 1
PHP Stack trace:
PHP   1. {main}() php shell code:0
PHP   2. define() php shell code:1
PHP Notice:  Use of undefined constant B - assumed 'B' in php shell code on line 1
PHP Stack trace:
PHP   1. {main}() php shell code:0
string(1) "B"


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2015-06-23 16:06 UTC] nikic@php.net
-Status: Open +Status: Closed -Package: PDO Core +Package: Scripting Engine problem -Assigned To: +Assigned To: nikic
 [2015-06-23 16:06 UTC] nikic@php.net
This will be supported in PHP 7.
 
PHP Copyright © 2001-2026 The PHP Group
All rights reserved.
Last updated: Wed Oct 07 05:00:01 2026 UTC