Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:60242 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 25621 invoked from network); 20 Apr 2012 18:10:36 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 20 Apr 2012 18:10:36 -0000 X-Host-Fingerprint: 208.107.13.98 host-98-13-107-208.midco.net Date: Fri, 20 Apr 2012 14:10:35 -0400 Received: from [208.107.13.98] ([208.107.13.98:20795] helo=localhost.localdomain) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 29/0A-63732-A96A19F4 for ; Fri, 20 Apr 2012 14:10:35 -0400 Message-ID: <29.0A.63732.A96A19F4@pb1.pair.com> To: internals@lists.php.net References: User-Agent: slrn/pre1.0.0-18 (Linux) X-Posted-By: 208.107.13.98 Subject: Re: [PHP-DEV] Complete case-sensitivity in PHP From: weierophinney@php.net (Matthew Weier O'Phinney) On 2012-04-20, Kris Craig wrote: > On Fri, Apr 20, 2012 at 8:44 AM, Sherif Ramadan wrote: > > > But in order to be case insensitive, PHP needs to know that > > > strtolower("A") == 'a'. So if you use Cyrilic for userland > > > functions/classes, php needs a cyrillic aware strtolower function. > > > Then the problem is that core classes/functions need to use a > > > plain ASCII strtolower for case insensitivity. So you cannot both > > > write code in cyrillic and interface with plain ASCII internals. > > > One possible, but less than optimal solution is to first try a > > > locale aware strtolower, then try a plain ascii strtolower when > > > looking up symbols. > > > > I can see the confusion about PHP's case-sensitivity and how it mixes > > and matches between case-insensitive functions/classes/(arguably even > > constants), and case-sensitive variable names, for example. > > > > Its naming rules are a little bit inconsistent in that regard. I just > > don't see a point in making it completely locale aware. The fact that > > you can do soefunc() and SOMEFUNC() and still invoke the same function > > is a benefit. > > Could you elaborate? Aside from making PHP forgiving of typos and overall > laziness on the part of the coder, and of course BC notwithstanding, I'm > not sure I understand what benefit there is to preserving this inconsistent > behavior. To make extensible and flexible systems, it's not uncommon to dynamically determine class and function or method names. This task is far simpler and less expensive if you don't need to worry about the casing of these names. As an example, I often see code like the following: public function setOptions(array $options) { foreach ($options as $key => $value) { $method = 'set' . $key; if (!method_exists($this, $method)) { continue; } $this->$method($value); } } This is trivial to implement and understand, and requires no need to transform the value of $key to an appropriately cased value in order to ensure the method name exists. Making method names case sensitive would break a ton of code, and require a ton of computational overhead as well as validation to make code like the above work. -- Matthew Weier O'Phinney Project Lead | matthew@zend.com Zend Framework | http://framework.zend.com/ PGP key: http://framework.zend.com/zf-matthew-pgp-key.asc