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
ClassMethodsHydrator::extract does not work with anonymous classes #25
Comments
The issue with providing a fix is that the Locally, as a proof-of-concept, I managed to fix the issue by creating a new Feedback from someone that has more in depth knowledge of this library would be essential. Thank you. |
This patch modifies filters slightly. Previously, they already checked to see if static property notation was provided or not. This extends that slightly to allow passing an optional second argument, a `null` or `object` value representing the instance being extracted or hydrated. For those filters that then use reflection, the `$instance` can be used as the primary argument, and the `$property` argument as the second. This approach allows the `ClassMethodsHydrator` to filter properly based on the specific instance under scrutiny. Additionally, this makes changes to `ClassMethodsHydrator` to: - Detect if an anonymous class was used. - Use the `spl_object_hash()` of that instance for caching the method list. - Pass the `$object` as the `$instance` argument to filters. Finally, I've added tests to each of the hydrators to verify they work as expected when presented with anonymous objects. Fixes laminas#25 Fixes laminas#26 Signed-off-by: Matthew Weier O'Phinney <matthew@weierophinney.net>
This patch modifies filters slightly. Previously, they already checked to see if static property notation was provided or not. This extends that slightly to allow passing an optional second argument, a `null` or `object` value representing the instance being extracted or hydrated. For those filters that then use reflection, the `$instance` can be used as the primary argument, and the `$property` argument as the second. This approach allows the `ClassMethodsHydrator` to filter properly based on the specific instance under scrutiny. Additionally, this makes changes to `ClassMethodsHydrator` to: - Detect if an anonymous class was used. - Use the `spl_object_hash()` of that instance for caching the method list. - Pass the `$object` as the `$instance` argument to filters. Finally, I've added tests to each of the hydrators to verify they work as expected when presented with anonymous objects. Fixes laminas#25 Fixes laminas#26 Signed-off-by: Matthew Weier O'Phinney <matthew@weierophinney.net>
This patch modifies filters slightly. Previously, they already checked to see if static property notation was provided or not. This extends that slightly to allow passing an optional second argument, a `null` or `object` value representing the instance being extracted or hydrated. For those filters that then use reflection, the `$instance` can be used as the primary argument, and the `$property` argument as the second. This approach allows the `ClassMethodsHydrator` to filter properly based on the specific instance under scrutiny. Additionally, this makes changes to `ClassMethodsHydrator` to: - Detect if an anonymous class was used. - Use the `spl_object_hash()` of that instance for caching the method list. - Pass the `$object` as the `$instance` argument to filters. Finally, I've added tests to each of the hydrators to verify they work as expected when presented with anonymous objects. Fixes laminas#25 Fixes laminas#26 Signed-off-by: Matthew Weier O'Phinney <matthew@weierophinney.net>
This patch modifies filters slightly. Previously, they already checked to see if static property notation was provided or not. This extends that slightly to allow passing an optional second argument, a `null` or `object` value representing the instance being extracted or hydrated. For those filters that then use reflection, the `$instance` can be used as the primary argument, and the `$property` argument as the second. This approach allows the `ClassMethodsHydrator` to filter properly based on the specific instance under scrutiny. Additionally, this makes changes to `ClassMethodsHydrator` to: - Detect if an anonymous class was used. - Use the `spl_object_hash()` of that instance for caching the method list. - Pass the `$object` as the `$instance` argument to filters. Finally, I've added tests to each of the hydrators to verify they work as expected when presented with anonymous objects. Fixes laminas#25 Fixes laminas#26 Signed-off-by: Matthew Weier O'Phinney <matthew@weierophinney.net>
This patch modifies filters slightly. Previously, they already checked to see if static property notation was provided or not. This extends that slightly to allow passing an optional second argument, a `null` or `object` value representing the instance being extracted or hydrated. For those filters that then use reflection, the `$instance` can be used as the primary argument, and the `$property` argument as the second. This approach allows the `ClassMethodsHydrator` to filter properly based on the specific instance under scrutiny. Additionally, this makes changes to `ClassMethodsHydrator` to: - Detect if an anonymous class was used. - Use the `spl_object_hash()` of that instance for caching the method list. - Pass the `$object` as the `$instance` argument to filters. Finally, I've added tests to each of the hydrators to verify they work as expected when presented with anonymous objects. Fixes laminas#25 Fixes laminas#26 Signed-off-by: Matthew Weier O'Phinney <matthew@weierophinney.net>
Bug Report
Summary
Using OptionalParametersFilter with an anonymous class fails saying a method does not exist.
Current behavior
The property FQN generated at
ClassMethodsHydrator.php:157
does not work for anonymous classes. For instance, in my case I get something like this:Consequently,
OptionalParametersFilter.php:48
fails because new ReflectionMethod can't locate it without an object.How to reproduce
See unit test:
#26
Expected behavior
Values to be properly extracted
Possible solutions
It seems we can't extract using the FQN but instead we need to use a reference to the object.
The text was updated successfully, but these errors were encountered: