Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PropertyAccessor - valid propertypath for array access with null value to be returned throws exception #12482

Closed
msumme opened this issue Nov 14, 2014 · 0 comments

Comments

@msumme
Copy link
Contributor

msumme commented Nov 14, 2014

This is in version 2.5.

I have an array like the following:

$myArray = ['property1' => ['property2' => null]];

If I call it throws an exception instead of returning null

$propertyAccessor = new PropertyAccessor(false, true);
$propertyAccessor->getValue($myArray, '[property1][property2]');
// NoSuchIndexException with message 'Cannot read property "property2". Available properties are "Array(
//  [0] => property2
// )
// ""

This is because line 232:
https://github.com/symfony/symfony/blob/2.5/src/Symfony/Component/PropertyAccess/PropertyAccessor.php#L232

It uses "isset()" instead of "array_key_exists" - and therefore falsely believes there is no property in the array - as isset() returns true on null values.

@msumme msumme changed the title Property Path terminating in null throws exception PropertyAccessor - valid propertypath for array access with null value to be returned throws exception Nov 14, 2014
fabpot added a commit that referenced this issue Jan 9, 2015
…kkooi)

This PR was merged into the 2.3 branch.

Discussion
----------

[PropertyAccessor] Allow null value for a array (2.3)

| Q             | A
| ------------- | ---
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #12482
| License       | MIT
| Doc PR        | -

Original PR is #12511
A rebase on 2.3 was requested by @fabpot

Commits
-------

9706b09 [PropertyAccessor] Added test to allow null value for a array
@fabpot fabpot closed this as completed Jan 9, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants