-
-
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
[Cache] PHP7.4 public typed properties cause cache clearing to crash #32465
Labels
Comments
tvandervorm
added a commit
to tvandervorm/symfony
that referenced
this issue
Jul 9, 2019
… default value, issue symfony#32465
tvandervorm
changed the title
PHP7.4 public typed properties cause cache clearing to crash
[Cache] PHP7.4 public typed properties cause cache clearing to crash
Jul 9, 2019
tvandervorm
added a commit
to tvandervorm/symfony
that referenced
this issue
Jul 9, 2019
PHP 7.4 is WIP. Would you like to submit a PR to fix this issue? |
tvandervorm
added a commit
to tvandervorm/symfony
that referenced
this issue
Jul 14, 2019
tvandervorm
added a commit
to tvandervorm/symfony
that referenced
this issue
Jul 14, 2019
tvandervorm
added a commit
to tvandervorm/symfony
that referenced
this issue
Jul 14, 2019
tvandervorm
added a commit
to tvandervorm/symfony
that referenced
this issue
Jul 14, 2019
fabpot
added a commit
that referenced
this issue
Jul 15, 2019
This PR was submitted for the 4.3 branch but it was squashed and merged into the 3.4 branch instead (closes #32466). Discussion ---------- [Config] Fix for signatures of typed properties | Q | A | ------------- | --- | Branch? | 4.3 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #32465 | License | MIT | Doc PR | - Also see the issue description, when using public typed properties ([new in PHP7.4](https://wiki.php.net/rfc/typed_properties_v2)) like this: ``` namespace App; class Foo { public int $bar; } ``` will cause `$defaults['bar']` not to be set in Symfony/Component/Config/Resource/ReflectionClassResource.php::139. This is because `$bar` doesn't have a default value, but does have a type hint, meaning it's default value is not `null` but undefined. This causes an 'undefined index' error when clearing the cache through `bin/console cache:clear` when running PHP7.4. The default value is used here for the class signature, having `null` should be appropriate for all cases. Commits ------- bad2a2c [Config] Fix for signatures of typed properties
Quick problem solving. (For example if you are upgrading from 3.4 -> 4.0) Initialize variable with |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Symfony version(s) affected: 4.*
Description
Clearing the cache when having a class with a public typed property (available from PHP 7.4) will cause the command to fail with the following error:
Where 'bar' is the name of the property. This is because the assumption is made that a default value is available for each property, which is
null
by default for untyped properties. However, for a typed propertynull
is no longer a valid value, so it will be undefined instead. Undefined default values are missing from$class->getDefaultProperties();
when doing reflection, hence the 'undefined index' error.How to reproduce
Generate a class like so:
save it in src/Foo.php and run
bin/console cache:clear
. Requires PHP7.4Possible Solution
The offending line is this one:
yield print_r($defaults[$p->name], true);
changing it so it accepts missing default values removes the error:
yield print_r($defaults[$p->name] ?? null, true);
Additional context
From the RFC:
The text was updated successfully, but these errors were encountered: