Skip to content

[PropertyAccess] Fix Usage with anonymous classes #23138

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

Closed

Conversation

mablae
Copy link
Contributor

@mablae mablae commented Jun 11, 2017

Replace forbidden characters in the the class names of Anonymous Classes in form of
class@anonymous /symfony/src/Symfony/Component/PropertyAccess/Tests/PropertyAccessorTest.php0x7f3f5f267ad5

Q A
Branch? master
Bug fix? yes
New feature? no
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets #23136
License MIT

@mablae mablae changed the title Fix Usage with anonymous classes [PropertyAccess] Fix Usage with anonymous classes Jun 11, 2017
@fabpot
Copy link
Member

fabpot commented Jun 12, 2017

As a bug fix, it should probably be merged in a lower branch (with a conditional test as not all supported PHP versions have anonymous class support).

* e.g. "class@anonymous /symfony/src/Symfony/Component/PropertyAccess/Tests/PropertyAccessorTest.php0x7f3f5f267ad5"
*
* @param string $class
* @return string
Copy link
Member

Choose a reason for hiding this comment

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

The two phpdocs should be removed.


$this->assertEquals($value, $propertyAccessor->getValue($obj, 'foo'));


Copy link
Member

Choose a reason for hiding this comment

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

Extra empty lines should be removed.

@mablae mablae force-pushed the fix-property-access-anon-classes branch from 6e2bfe6 to ad6e86a Compare June 12, 2017 19:57
@mablae
Copy link
Contributor Author

mablae commented Jun 12, 2017

@fabpot Thanks for your feedback.

What about the the strpos check? Not good enough? Should I check for the PHP Version, too?

Which branch is the lowest possible to patch this in?

@@ -433,7 +433,7 @@ private function readProperty($zval, $property)
*/
private function getReadAccessInfo($class, $property)
{
$key = $class.'..'.$property;
$key = $this->sanitizeAnonymousClassName($class).'..'.$property;
Copy link
Member

Choose a reason for hiding this comment

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

since this is perf critical, I suggest inline here, and use the fastest, which is rawurlencode. This might look like:
rawurlencode($class)
or
false !== strpos($class, '@') ? rawurlencode($class) : $class

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the review@nicolas-grekas. I will implement it like you suggested then.

@mablae mablae force-pushed the fix-property-access-anon-classes branch from f39fbd2 to 1400457 Compare June 12, 2017 22:03
{
if (PHP_MAJOR_VERSION < 7) {
$this->markTestSkipped('Anonymous Classes are only supported on PHP7');
return;
Copy link
Member

Choose a reason for hiding this comment

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

we prefer using @requires php 7 annotations
this made me notice that this should be submitted (rebased+base branch changed) against the 3.3 branch

*/
private function generateAnonymousClass($value)
{
$obj = new class($value)
Copy link
Member

Choose a reason for hiding this comment

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

This should trigger a parse error on php<7 - thus should be moved to a dedicated fixture file or be replaced in an eval()

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ouch... Sorry, i will look into it.

I have no 5.x System ready to test it right now

Replace forbidden characters in the the class names of Anonymous Classes in form of
"class@anonymous /symfony/src/Symfony/Component/PropertyAccess/Tests/PropertyAccessorTest.php0x7f3f5f267ad5"
@mablae
Copy link
Contributor Author

mablae commented Jun 13, 2017

Closing in favor of #23155

@mablae mablae closed this Jun 13, 2017
@mablae mablae deleted the fix-property-access-anon-classes branch June 13, 2017 08:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants