-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
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] Throw exception on nonexistant "index" on read access #7881
Comments
I think we should throw an exception if an index does not exist. But we maybe need to put this also in a builder, to prevent BC breaks. For the exception, I think it should be |
I think that your proposal is very good. In particular:
👍 I think you should create a common super-class for the NoSuch*Exceptions, for example AccessException. Then it is possible to either catch both exceptions in one clause or to catch them in two separate clauses. |
I'll do it and see what other people think about that. |
Hi again, I've made a new commit. You can see changes here : https://github.com/sescandell/symfony/commits/patch-property_accessor_exception @wouterj > I taked into account what you said and this feature is available throught the PropertyAccessorBuilder (already existing in the component). Thanks to that, there is no more BC Break. @bschussek > In fact, NoSuch*Exception both extends RuntimeException... Do you think we really need to create an intermediate common class? |
thank you! Could you please create a PR, that makes it easier to disuss and review the patch. And I agree with @bschussek, we should have a common class. |
@sescandell RuntimeException can be used for something else than AccessException. So catching all RuntimeException would not be equivalent to catching both NoSuch*Exception. This is why we would need the intermediate AccessException |
…" on read access (fabpot) This PR was merged into the master branch. Discussion ---------- [PropertyAccessor] Throw exception on nonexistant "index" on read access | Q | A | ------------- | --- | Bug fix? | no | New feature? | a kind of? | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | 7881 | License | MIT | Doc PR | See discussion on issue #7881. Commits ------- e73742a [PropertyAccess] Throw exception on nonexistant "index" on read access
Currently, in the PropertyAccessor, if we try to get a nonexistent property from an array, PropertyAccessor will success and return a null value.
IMO, this is not logical compared to object behavior. In an object context, if property doesn't exist, it throws a NoSuchPropertyException exception.
I've made a patch for that taking into account read or write context for array.
Before making a PR, I would like to discuss it.
Tests\PropertyAccessorTest::testGetValueReadsArrayWithMissingIndexForCustomPropertyPath
(wich is normal). In my patch I fixed it.Commit concerned available here: sescandell@2e35cd7
Waiting for you comments.
The text was updated successfully, but these errors were encountered: