Re: [RFC] Bare Name Array

From: Date: Sun, 01 Jun 2014 18:56:13 +0000
Subject: Re: [RFC] Bare Name Array
References: 1 2 3 4 5  Groups: php.internals 
Request: Send a blank email to internals+get-74672@lists.php.net to get a copy of this message
You missed my point, I'm not saying about undefined constants, I'm saying about the usage of defined constants as array keys. If the array declaration don't expand constants to strings anymore, many code will break. If we expand constants within array declaration, someone can mess up the code by adding a define() somewhere above and don't even realize what's wrong (constants have global scope). On Sun, Jun 1, 2014 at 3:49 PM, Andrea Faulds <ajf@ajf.me> wrote: > > On 1 Jun 2014, at 19:47, Rafael Kassner <kassner@php.net> wrote: > > > This causes a huge backward incompatibility: > > > > define('KEY', 'foo'); > > $data = array(KEY => 'bar'); > > > > Should $data have 'foo' or 'KEY' as element? AFAIK, some frameworks > > use > this constants in array keys. > > ‘foo’, I checked. Frameworks doing that should really not be, it’s really > bad practise to rely on PHP’s fallback for non-existent constants, and that > generates a Notice. > > Now you’d have the option of doing array(KEY: ‘bar’) though, which does > not resolve the constant. > -- > Andrea Faulds > http://ajf.me/ > > > > >

« previous php.internals (#74672) next »