3

I upgrade my project from SF 5.4 to SF 6 with php 8.1.2.

With my dev env I have no errors!

When I use the prod env when I cache clear I have the error:

In Route.php line 196:
                                                                                                              
  Typed property Symfony\Component\Routing\Annotation\Route::$env must not be accessed before initialization  

I try to remove the var/cache folder.

Do you have any ideas how to fix that one?

I found the same error in stack and I replace the handler_id with null value.

The error come from the SF router vendor. Route.php is not my own code.

Sancho
  • 1,288
  • 2
  • 25
  • 50
  • Possible duplicate of: [Why I am suddenly getting a "Typed property must not be accessed before initialization" error when introducing properties type hints?](https://stackoverflow.com/questions/59265625/why-i-am-suddenly-getting-a-typed-property-must-not-be-accessed-before-initiali) – Luuk May 14 '22 at 09:21
  • 1
    I know the error .... I don't know why I get that one in a SF vendor. This IS NOT a duplicate – Sancho May 14 '22 at 09:22
  • Print `$env` in your development environment and see which value it has. Then try to determine why it is unset in your production environment. See https://madewithlove.com/blog/software-engineering/typed-property-must-not-be-accessed-before-initialization/ – Franck May 14 '22 at 09:45
  • I guess you ever tried to rm -rf your vendor and run composer install again – Guillaume Harari May 15 '22 at 15:21
  • I tried to remove and reinstall the vendors :) – Sancho May 16 '22 at 06:29
  • I had the same error on PHP 8.0.10 while upgrading 5.4 to 6.0. cache:clear always threw that error. After upgrading recipes and manually removing cache folder, cache:clear was [OK]. Also see https://github.com/symfony/symfony/issues/45802 – tdd May 27 '22 at 09:57

1 Answers1

4

I have had the same issue so I cleared cache typing this command symfony console cache:clear to make all work again. You can also refer to this link if the need arises: $env not initialized

Joe Pierre
  • 49
  • 1
  • 5
  • 1
    Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Aug 02 '22 at 04:58
  • nice - worked - thanks for the hint +1 – Corepex Nov 15 '22 at 10:33
  • @Corepex can you explain how this worked for you?? The problem in the question is that the error occurs when running cache:clear, and you solved it by running cache:clear? – matteo Jun 10 '23 at 18:28