On Sat, Jan 5, 2013 at 3:07 PM, Nikita Nefedov <inefe...@gmail.com> wrote:
> What symbols can give: > 1. More convenient way to use it almost everywhere as a replacement for > strings and sometimes for constants. There's a lot of code that uses arrays > as a parameter-stores. For example, here's how you usually define a form in > Symfony2: > $builder > ->add('title', 'text', array( > 'label' => 'Album title' > )) > ->add('title_alias', 'text', array( > 'label' => 'Album alias', > 'required' => false, > 'property_path' => 'properties.titleAlias' > )) > ->add('comment', 'text', array( > 'label' => 'Comment', > 'required' => false, > 'property_path' => 'properties.comment' > )) > ->add('labels', 'text', array( > 'label' => 'Musical labels', > 'required' => false, > 'property_path' => 'properties.labels' > )) > ->add('language', 'text', array( > 'required' => false, > 'property_path' => 'properties.language' > )) > It could be improved this way: > $builder > ->add('title', :text, array( > :label => 'Album title' > )) > ->add('title_alias', :text, array( > :label => 'Album alias', > :required => false, > :property_path => 'properties.titleAlias' > )) > ->add('comment', :text, array( > :label => 'Comment', > :required => false, > :property_path => 'properties.comment' > )) > ->add('labels', :text, array( > :label => 'Musical labels', > :required => false, > :property_path => 'properties.labels' > )) > ->add('language', :text, array( > :required => false, > :property_path => 'properties.language' > )) > 2. Memory usage reduction. AFAIK, there's a lot of cases like the above > and the use of symbols would affect on memory usage significantly. > 3. Memory leaks. Symbols can't be just garbage collected as, for example > zvals, it's not possible. But we can do it for every request, so I don't > think it would be problem. > 4. Autocompletion from IDEs. > Hi Nikita! I don't quite understand what those symbols would actually be good for. If it's just for saving exactly one character for array keys (:foo vs "foo"), then this isn't worth it. If this is about memory savings, then I don't think it will help at all. PHP uses interned strings, so all those "label" etc strings in your above example actually use the same string value. The hash for those strings is also precomputed, so symbol don't have a performance advantage either. Regarding your fourth point, autocompletion is available for string array keys at least in PhpStorm and I guess also in other IDEs. So, I don't yet really get what the point behind the symbols is. Thanks, Nikita