Skip to content

[PropertyInfo] Fix an error in PropertyInfoCacheExtractor #19437

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
wants to merge 2 commits into from

Conversation

GuilhemN
Copy link
Contributor

@GuilhemN GuilhemN commented Jul 26, 2016

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

An argument was forgotten in the PropertyInfoCacheExtractor class leading to exceptions such as

PHP Warning:  ucfirst() expects parameter 1 to be string, array given in /home/guilhem/github/ast-test/vendor/symfony/symfony/src/Symfony/Component/PropertyInfo/Extractor/ReflectionExtractor.php on line 318

and making it unusable.

ping @dunglas

@dunglas
Copy link
Member

dunglas commented Jul 26, 2016

👍

Can you add a non-regression test please?

@GuilhemN GuilhemN force-pushed the patch-3 branch 4 times, most recently from 2e351de to 70a8de2 Compare July 26, 2016 17:35
@GuilhemN
Copy link
Contributor Author

@dunglas done :)
BTW this shows how much php7 type hints are useful ! I hope symfony 4 will remove php5 support.

@theofidry
Copy link
Contributor

BTW this shows how much php7 type hints are useful !

Or any good static code analyzer for that matter :P

@GuilhemN
Copy link
Contributor Author

@theofidry yes of course (but it is slower) :P

@GuilhemN
Copy link
Contributor Author

GuilhemN commented Jul 27, 2016

I found another bug but I don't know why it happens...
This condition is never true and the psr cache is always used.
Using array_key_exists solves this issue. Any idea ?

Edit: Ok it happens when the extractor returns null. I'll submit a commit.

@theofidry
Copy link
Contributor

did you try to dump the value?

@theofidry
Copy link
Contributor

@Ener-Getick any idea of what the isset was not working?

@GuilhemN
Copy link
Contributor Author

@theofidry yes sorry i forgot to answer you as i updated my message...
Isset is kind of equals to null !== @$value so when the value cached is null, isset returns false whereas array_key_exists which returns true as long as the value exists.

@theofidry
Copy link
Contributor

IIRC null is not cached in most cache systems, shouldn't we avoid to cache it here as well?

@GuilhemN
Copy link
Contributor Author

GuilhemN commented Jul 27, 2016

@theofidry it is cached in the cross requests cache but it is not fetched in the array cache which is only here because it is faster than the first one. So it will be cached anyway the only thing changing are the performances.

@GuilhemN GuilhemN closed this Jul 27, 2016
@GuilhemN GuilhemN reopened this Jul 27, 2016
private function assertIsString($string)
{
if (!is_string($string)) {
throw new \Exception(sprintf('"%s" expects strings, given "%s".', __CLASS__, gettype($string)));
Copy link
Member

Choose a reason for hiding this comment

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

InvalidArgumentException?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It doesn't matter that much as it's a fixture but it's indeed more adapted here.
updated :)

@GuilhemN
Copy link
Contributor Author

Should I change something else ?

@dunglas
Copy link
Member

dunglas commented Aug 11, 2016

Ok for me. I'll merge it when I'll be back from vacation.

@nicolas-grekas
Copy link
Member

👍
Status: reviewed

@fabpot
Copy link
Member

fabpot commented Aug 15, 2016

Thank you @Ener-Getick.

fabpot added a commit that referenced this pull request Aug 15, 2016
…(Ener-Getick)

This PR was squashed before being merged into the 3.1 branch (closes #19437).

Discussion
----------

[PropertyInfo] Fix an error in PropertyInfoCacheExtractor

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

An argument was forgotten in the ``PropertyInfoCacheExtractor`` class leading to exceptions such as
```
PHP Warning:  ucfirst() expects parameter 1 to be string, array given in /home/guilhem/github/ast-test/vendor/symfony/symfony/src/Symfony/Component/PropertyInfo/Extractor/ReflectionExtractor.php on line 318
```
and making it unusable.

ping @dunglas

Commits
-------

d19b151 [PropertyInfo] Fix an error in PropertyInfoCacheExtractor
@fabpot fabpot closed this Aug 15, 2016
@GuilhemN GuilhemN deleted the patch-3 branch August 22, 2016 12:54
@fabpot fabpot mentioned this pull request Sep 3, 2016
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.

6 participants