Issues

ZF-7742: getOption not working with uppercase $key

Issue Type: Bug Created: 2009-08-31T15:34:50.000+0000 Last Updated: 2009-10-13T17:57:42.000+0000 Status: Resolved Fix version(s): - 1.9.3 (22/Sep/09)

Reporter: Michiel Thalen (chielsen) Assignee: Matthew Weier O'Phinney (matthew) Tags: - Zend_Application

Related issues: - ZF-6679

Attachments: - 7742.patch

Description

<pre class="highlight">
    public function getOption($key)
    {
        if ($this->hasOption($key)) {
            $options = $this->getOptions();
            $options = array_change_key_case($options, CASE_LOWER);
            return $options[strtolower($key)];
        }
        return null;
    }

hasOption() is case sensitve so it never gets to the strtolowerpart

2 possible solutions:

make getOption() like this:

<pre class="highlight">
    public function getOption($key)
    {
       $key = strtolower($key);
        if ($this->hasOption($key)) {
            $options = $this->getOptions();
            $options = array_change_key_case($options, CASE_LOWER);
            return $options[($key];
        }
        return null;
    }

Or make hasOption, since all options get loaded into lowercase keys anyway:

<pre class="highlight">
    public function hasOption($key)
    {
        return in_array(strtolower($key), $this->_optionKeys);
    }

Comments

Posted by Travis Pew (travisp) on 2009-09-18T05:49:42.000+0000

This is related to ZF-6679

Basically, the intention was that getOptions would preserve the original case, but lookups (getOption and hasOption) would work if you supply a lowercase key or a case sensitive key.

But, passing a key with a capital letter does not work.

Posted by Travis Pew (travisp) on 2009-09-18T05:58:00.000+0000

Unit tests and fix to allow passing keys with capital letters to getOption and hasOption. getOption didn't need a fix since it was already coded to be case-insensitive, but relied on hasOption which was case-sensitive.

Posted by Benjamin Eberlei (beberlei) on 2009-09-18T06:12:15.000+0000

I agree with Travis that hasOption is missing the strtolower functionality and therefore this bug occurs.

Posted by Matthew Weier O'Phinney (matthew) on 2009-09-18T12:46:00.000+0000

Fixed in trunk and 1.9 release branch

Posted by Michiel Thalen (chielsen) on 2009-10-13T15:24:53.000+0000

How come i don't see it in the repository?

Posted by Dolf Schimmel (Freeaqingme) (freak) on 2009-10-13T15:31:58.000+0000

Look here: http://framework.zend.com/code/viewrep/…

Posted by Michiel Thalen (chielsen) on 2009-10-13T17:57:42.000+0000

Ah, but it is still missing in BootstrapAbstract.php

Have you found an issue?

See the Overview section for more details.

Copyright

© 2006-2016 by Zend, a Rogue Wave Company. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.

Contacts