On 2012-04-20, Kris Craig <kris.cr...@gmail.com> wrote:
> On Fri, Apr 20, 2012 at 8:44 AM, Sherif Ramadan <theanomaly...@gmail.com> 
> 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            | matt...@zend.com
Zend Framework          | http://framework.zend.com/
PGP key: http://framework.zend.com/zf-matthew-pgp-key.asc

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to