Skip to content
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

[RFC] Allow to use PHP 7.4 typed class properties #478

Closed
hermann8u opened this issue Oct 14, 2019 · 7 comments
Closed

[RFC] Allow to use PHP 7.4 typed class properties #478

hermann8u opened this issue Oct 14, 2019 · 7 comments
Labels

Comments

@hermann8u
Copy link

hermann8u commented Oct 14, 2019

PHP 7.4 and Symfony 5.0 release dates are at the end of november 2019. One of the biggest improvement expected by many developers in this PHP version is the ability to type class properties. However, I heard that Symfony 5.0 will supports only PHP 7.2.

Is there any plan to generate code with typed properties?

I thought about it a little bit and I see the following options :

  1. Read the content of the composer.json to detect which version of PHP is used.
    If the version is superior to 7.4, then use by default the class properties. The main drawback is that typed properties would be imposed to users, but I guess it's fine since this bundle aims to promote good practices.

  2. Add configuration to the bundle
    I know that this bundle doesn't have configuration yet and I understand that the goal is to generate something really straight forward. That's why it's maybe not the right choice. However, this configuration could be located in the composer.json under an "extra.symfony.allow_typed_properties" key or something like that.

  3. Ask dynamically during the execution of the command
    This option has the advantage to let the user make the choice but it could be redundant.

  4. A mix of the previous options
    Check if the composer.json contains a PHP version > 7.4, then ask dynamically to the user during the execution of a type related command if he wants to use typed properties and then register in the composer.json the choice.

  5. Do nothing / None of the above options

I don't know if such a feature is a good idea or not, but I think it's worth a discussion. I realised that it will imply a lot of work too, and it might be not worth the pain.

What do you think about it?

@hermann8u hermann8u changed the title RFC: Allow to use PHP 7.4 typed class properties [RFC] Allow to use PHP 7.4 typed class properties Oct 14, 2019
@LeJeanbono
Copy link
Contributor

FYI : symfony/symfony#32179

@hermann8u
Copy link
Author

FYI : symfony/symfony#32179

Sorry, but I don't think it's related. It concerns the MakerBundle and the ability to generate code with typed properties in it.

@LeJeanbono
Copy link
Contributor

I know, it's just to show all the reflection by the symfony team

@javiereguiluz
Copy link
Member

@hermann8u thanks for this proposal. I'm not answering to it yet ... but I'd like to comment that @LeJeanbono is right in the sense that the MakerBundle always does what the main Symfony repo does (same code syntax, same PHP version requirements, same best practices for generated code, etc.)

@stof
Copy link
Member

stof commented Oct 15, 2019

Well, Symfony 5.0 won't use Typed Properties, as the min requirement is PHP 7.2.

@stof
Copy link
Member

stof commented Oct 15, 2019

One thing is needed in MakerBundle though, given that it can be used to modify existing entities and not just create some: we need to make sure it can edit an entity which uses typed properties without failing (and without removing the existing types). Maybe that's already the case thanks to PHP-Parser, but that should be checked (and probably added to the testsuite).

@nicolas-grekas
Copy link
Member

Closing as there is nothing specific to keep track of.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

6 participants