Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:64565 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 16343 invoked from network); 5 Jan 2013 22:49:30 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 5 Jan 2013 22:49:30 -0000 Authentication-Results: pb1.pair.com smtp.mail=smalyshev@sugarcrm.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=smalyshev@sugarcrm.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain sugarcrm.com designates 67.192.241.163 as permitted sender) X-PHP-List-Original-Sender: smalyshev@sugarcrm.com X-Host-Fingerprint: 67.192.241.163 smtp163.dfw.emailsrvr.com Linux 2.6 Received: from [67.192.241.163] ([67.192.241.163:60630] helo=smtp163.dfw.emailsrvr.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id DC/D9-62408-9FDA8E05 for ; Sat, 05 Jan 2013 17:49:29 -0500 Received: from localhost (localhost.localdomain [127.0.0.1]) by smtp6.relay.dfw1a.emailsrvr.com (SMTP Server) with ESMTP id 13A7227025C; Sat, 5 Jan 2013 17:49:27 -0500 (EST) X-Virus-Scanned: OK Received: by smtp6.relay.dfw1a.emailsrvr.com (Authenticated sender: smalyshev-AT-sugarcrm.com) with ESMTPSA id 7AB6027024C; Sat, 5 Jan 2013 17:49:26 -0500 (EST) Message-ID: <50E8ADF5.6070504@sugarcrm.com> Date: Sat, 05 Jan 2013 14:49:25 -0800 Organization: SugarCRM User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:17.0) Gecko/17.0 Thunderbird/17.0 MIME-Version: 1.0 To: Nikita Nefedov CC: "internals@lists.php.net" References: In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] Ruby's symbols From: smalyshev@sugarcrm.com (Stas Malyshev) Hi! > I know I shouldn't write "Ruby" in the subject of a letter for > php-internals ML, but... Just wanted to ask, is anybody interested in this > feature in PHP? As I understand, :foo is basically an interned string "foo". But in PHP all constant strings are interned now, so the only thing we gain is comparison speed. Given that the strings we're talking about is under 10 chars, performance gain from this would be negligible, and symbols aren't frequently directly compared anyway. So what exactly we're gaining that is not there in just constant string? > $foo = array(); > $foo[:bar] = "qwerty"; > > var_dump($foo); > // array(1) { > // [0] => > // string(6) "qwerty" > //} Here's a problem. How we know that :bar is 0? What if we serialized $foo and later loaded it back - would :bar still be 0? Would :bar be 0 in all scripts forever - and if not, how would we know where $foo[:bar] is actually stored when we combine two scripts? I think it can not work this way since link between :bar and actual hash key should be stable. > I will drop the part about new variable type, the main thing is how > HashTables could work with symbols as keys. HashTable can accept only string or number as key. As we have seen before, making number from :bar is very hard to pull off properly. And if we use string "bar", why not just use string "bar"? > 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: How it's more convenient? I don't see any difference. > 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. I don't see any memory usage reduction - you still have to store the string. Could you explain how memory usage is reduced? -- Stanislav Malyshev, Software Architect SugarCRM: http://www.sugarcrm.com/ (408)454-6900 ext. 227