Zend Framework

getOption not working with uppercase $key

Details

  • Type: Bug Bug
  • Status: Resolved Resolved
  • Priority: Minor Minor
  • Resolution: Fixed
  • Affects Version/s: 1.9.2
  • Fix Version/s: 1.9.3
  • Component/s: Zend_Application
  • Labels:
    None

Description

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:

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:

public function hasOption($key)
    {
        return in_array(strtolower($key), $this->_optionKeys);
    }

Issue Links

Activity

Hide
Travis Pew added a comment -

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.

Show
Travis Pew added a comment - 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.
Hide
Travis Pew added a comment -

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.

Show
Travis Pew added a comment - 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.
Hide
Benjamin Eberlei added a comment -

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

Show
Benjamin Eberlei added a comment - I agree with Travis that hasOption is missing the strtolower functionality and therefore this bug occurs.
Hide
Matthew Weier O'Phinney added a comment -

Fixed in trunk and 1.9 release branch

Show
Matthew Weier O'Phinney added a comment - Fixed in trunk and 1.9 release branch
Hide
Michiel Thalen added a comment -

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

Show
Michiel Thalen added a comment - How come i don't see it in the repository?
Hide
Michiel Thalen added a comment -

Ah, but it is still missing in BootstrapAbstract.php

Show
Michiel Thalen added a comment - Ah, but it is still missing in BootstrapAbstract.php

People

Vote (0)
Watch (1)

Dates

  • Created:
    Updated:
    Resolved:

Time Tracking

Estimated:
Not Specified
Original Estimate - Not Specified
Remaining:
0m
Remaining Estimate - 0 minutes
Logged:
1m
Time Spent - 1 minute