Task #254
Input::get() returning values which doesn't really exist
| Status: | Closed | Start date: | 2010-03-28 | |
|---|---|---|---|---|
| Priority: | Medium | Due date: | ||
| Assignee: | Alex Cartwright | % Done: | 100% |
|
| Category: | - | |||
| Target version: | 2.6.0 | |||
| PHP Version: |
Description
2.5.0
Input class line 255, function get():
} else if ( isset( $tmpVal[ $val ] ) ) {
isset($array['non_existing_key']) returns true if $array exists.
Go to URL: ?first=third
echo Registry::get('input')->get('first/second');
Will display 'third'. As long as 'first' is in the first level of the multidimensional GET/POST variable you want to access, it doesn't matter how many subsequent slashes you add when calling Input::get().
A solution could be:
} else if ( isset( $tmpVal[ $val ] ) && is_array( $tmpVal[ $val ] ) ) {
which would correctly throw Input_KeyNoExist when trying to access 'first/second' in the example above.
History
Updated by Alex Cartwright almost 2 years ago
- Status changed from New to Confirmed
- Assignee set to Alex Cartwright
- Priority changed from Undecided to Medium
Weird ... ok, confirmed here. A brief look at your solution and I am not convinced that would fix it and maintain expected behaviour of other scripts. Going to look into it now. Thanks
Updated by Alex Cartwright almost 2 years ago
- Status changed from Confirmed to Closed
- % Done changed from 0 to 100
Applied in changeset commit:"1cf127a8834fb86551069229f699ef451bd41a58".
Updated by Alex Cartwright almost 2 years ago
Just to confirm the behaviour you were seeing; Passing in URL query arguments such as 'foo=bar' and then doing
echo Registry::get( 'input' )->get( 'foo/cake' );
would echo 1. This is because of how PHP handles strings, and the ability to access a specific char using [] as can be seen here:
php > $foo = 'bar'; php > var_dump( $foo[0], (int) 'cake', $foo['cake'] ); string(1) "b" int(0) string(1) "b"
Updated by Alex Cartwright almost 2 years ago
- Tracker changed from Bug to Task