Bug #69913 [Opn->Csd]: arrays are allowed in 'const' but not 'define'

From: Date: Tue, 23 Jun 2015 16:06:47 +0000
Subject: Bug #69913 [Opn->Csd]: arrays are allowed in 'const' but not 'define'
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-193810@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=69913&edit=1 ID: 69913 Updated by: nikic@php.net Reported by: gordon dot mcvey at ntlworld dot com Summary: arrays are allowed in 'const' but not 'define' -Status: Open +Status: Closed Type: Bug -Package: PDO Core +Package: Scripting Engine problem Operating System: OSX 10.10.3 PHP Version: 5.6.10 -Assigned To: +Assigned To: nikic Block user comment: N Private report: N New Comment: This will be supported in PHP 7. Previous Comments: ------------------------------------------------------------------------ [2015-06-23 16:04:43] 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" ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=69913&edit=1

« previous php.bugs (#193810) next »