Skip to content

[2.5][PropertyAccess] Fixed getValue() when accessing non-existing indices of ArrayAccess implementations #10946

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

Merged
merged 1 commit into from
May 21, 2014

Conversation

webmozart
Copy link
Contributor

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

Previously, when the following code was executed:

$object = new ImplOfArrayAccess();

$propertyAccessor->setValue($object, '[index]', 'Value');

and that index did not exist, a fatal error would be generated because array_keys() was executed on $object. This error is fixed now.

throw new NoSuchIndexException(sprintf(
'Cannot read property "%s". Available properties are "%s"',
$property,
print_r(array_keys($objectOrArray), true)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you sould keep it on 1 line, like previously

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@webmozart why use print_r? It prints way more than the available keys.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Tobion Good question, actually. I kept the previous code, which was like this.

@stof I prefer to be able to actually read the line. Overall, we use both.

@stof
Copy link
Member

stof commented May 20, 2014

shoudln't this one be closed in favor of #10947 ?

@webmozart
Copy link
Contributor Author

@stof No, one of the PRs is for 2.4, the other for master. Applying the 2.4 version to master is non-trivial, which is why I created separate PRs.

fabpot added a commit that referenced this pull request May 21, 2014
…existing indices of ArrayAccess implementations (webmozart)

This PR was merged into the 2.4 branch.

Discussion
----------

[2.4][PropertyAccess] Fixed getValue() when accessing non-existing indices of ArrayAccess implementations

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

This PR backports two test refactoring commits from the master branch. The third commit is basically the same as #10946.

Commits
-------

5b5a6b6 [PropertyAccess] Fixed getValue() when accessing non-existing indices of ArrayAccess implementations
91ee821 [PropertyAccess] Refactored PropertyAccessorCollectionTest
5614303 [PropertyAccess] Refactored PropertyAccessorTest
@webmozart
Copy link
Contributor Author

Updated, removed the "return null" statement.

@fabpot fabpot merged commit fef698e into symfony:master May 21, 2014
fabpot added a commit that referenced this pull request May 21, 2014
…existing indices of ArrayAccess implementations (webmozart)

This PR was merged into the 2.5-dev branch.

Discussion
----------

[2.5][PropertyAccess] Fixed getValue() when accessing non-existing indices of ArrayAccess implementations

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

Previously, when the following code was executed:

```php
$object = new ImplOfArrayAccess();

$propertyAccessor->setValue($object, '[index]', 'Value');
```

and that index did not exist, a fatal error would be generated because `array_keys()` was executed on `$object`. This error is fixed now.

Commits
-------

fef698e [PropertyAccess] Fixed getValue() when accessing non-existing indices of ArrayAccess implementations
@webmozart webmozart deleted the issue10705-2.5 branch August 4, 2014 14:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants