Can you explain me, why you don't suggest on doctrine repository to typeHint $query with string ? So next time someone has this error, he could have a clean Error.
Ah, an excellent question! Until recently, Symfony's code base did not include scalar type-hints at all. There were two reasons for this:
1) Symfony was compatible with older versions of PHP (that did not support type-hints) and so type-hints couldn't be added until Symfony required only PHP 7.1 or higher (which happened with Symfony 4).
2) Type-hints need to be added very carefully, as adding a type-hint to a method can often be a backwards-compatibility break. For example, if a user sub-classed the Connection class we looked at and overrode this executeUpdate() method, then I think (but I could be wrong... but it's still a good "example") that if Symfony added the string type-hint, it would break their implementation. Anyways, type-hints have started to be added to Symfony, but it required some new internal systems to "deprecate" not adding the type-hint if you sub-class a method where we want to add one... so that in 5.0 we can truly add them everywhere.
So... it's a simple question... with a not-so-simple answer. Type-hints are great. But Symfony's backwards-compatibility promise (which makes Symfony great!) sometimes means that seemingly-simple changes require bigger thought.
Good question! Yes, it's possible, you can specify a specific version after colon, or use "v4.1." to install the latest version of 4.1:
`
composer create-project 'symfony/skeleton:v4.1.' triage_issue_27901 `
Cheers!
Please, log in to vote for this comment
|
Share Comment
"Houston: no signs of life" Start the conversation!
The concepts in this tutorial work great for Symfony 5!
4 Comments
Hello,
Can you explain me, why you don't suggest on doctrine repository to typeHint $query with string ?
So next time someone has this error, he could have a clean Error.
Or this is a bad idea for some reason ?
Best regards
Hey Jérôme B.!
Ah, an excellent question! Until recently, Symfony's code base did not include scalar type-hints at all. There were two reasons for this:
1) Symfony was compatible with older versions of PHP (that did not support type-hints) and so type-hints couldn't be added until Symfony required only PHP 7.1 or higher (which happened with Symfony 4).
2) Type-hints need to be added very carefully, as adding a type-hint to a method can often be a backwards-compatibility break. For example, if a user sub-classed the
Connectionclass we looked at and overrode thisexecuteUpdate()method, then I think (but I could be wrong... but it's still a good "example") that if Symfony added the string type-hint, it would break their implementation. Anyways, type-hints have started to be added to Symfony, but it required some new internal systems to "deprecate" not adding the type-hint if you sub-class a method where we want to add one... so that in 5.0 we can truly add them everywhere.So... it's a simple question... with a not-so-simple answer. Type-hints are great. But Symfony's backwards-compatibility promise (which makes Symfony great!) sometimes means that seemingly-simple changes require bigger thought.
Cheers!
Hi Ryan,
How is possible to install Sf 4.1 now that Sf 4.2 is the current version ? Thank.
Hey Stephane,
Good question! Yes, it's possible, you can specify a specific version after colon, or use "v4.1." to install the latest version of 4.1: ` composer create-project 'symfony/skeleton:v4.1.' triage_issue_27901
`
Cheers!
"Houston: no signs of life"
Start the conversation!