Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:64546 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 35972 invoked from network); 5 Jan 2013 12:21:30 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 5 Jan 2013 12:21:30 -0000 Authentication-Results: pb1.pair.com smtp.mail=nikita.ppv@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=nikita.ppv@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.215.41 as permitted sender) X-PHP-List-Original-Sender: nikita.ppv@gmail.com X-Host-Fingerprint: 209.85.215.41 mail-la0-f41.google.com Received: from [209.85.215.41] ([209.85.215.41:46662] helo=mail-la0-f41.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id AA/EE-38386-9CA18E05 for ; Sat, 05 Jan 2013 07:21:30 -0500 Received: by mail-la0-f41.google.com with SMTP id em20so11365563lab.28 for ; Sat, 05 Jan 2013 04:21:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=1+b8AS4MMDtwhb7t345kFuXdcruqREWEy2p/HGltASQ=; b=LCfUOhnHbxX1kARGUNcKSy7LDfyw2/d4KwlBhRXJk889DDFAyCvZyCAy3tWGvwH9IH r4Cfa8EISxgHF5rPpaNuqDu6av+iBsK/39HFozAmgyCLx6zbPqKckMiz3zl1f16W90ek 0ev8vBd7eWsbVjykgIf2iJHh0jqirUmrkxbh94o/oSWRS3PZEdroQPm410gQYwCywrRc 3sxeWlO8Tp61w844TNLASqmVJodC1PRxx2RgVDOxDl4L2SySZUUj3C6ieT3XXwAuLB/I 2CyqZ/qsx6T4ikg+BuYmep0mJFp1NDkRypzZ3l/MsAgvJHFLB331moQ0D0j/LCR4enAr Ngrw== MIME-Version: 1.0 Received: by 10.112.10.200 with SMTP id k8mr15203124lbb.73.1357388486493; Sat, 05 Jan 2013 04:21:26 -0800 (PST) Received: by 10.112.4.168 with HTTP; Sat, 5 Jan 2013 04:21:26 -0800 (PST) In-Reply-To: References: Date: Sat, 5 Jan 2013 13:21:26 +0100 Message-ID: To: Nikita Nefedov Cc: "internals@lists.php.net" Content-Type: multipart/alternative; boundary=bcaec54ee2908f473f04d289a2aa Subject: Re: [PHP-DEV] Ruby's symbols From: nikita.ppv@gmail.com (Nikita Popov) --bcaec54ee2908f473f04d289a2aa Content-Type: text/plain; charset=ISO-8859-1 On Sat, Jan 5, 2013 at 3:07 PM, Nikita Nefedov 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 --bcaec54ee2908f473f04d289a2aa--