nette / php-generator

🐘 Generates neat PHP code for you. Supports new PHP 8.3 features.
https://doc.nette.org/php-generator
Other
2.11k stars 138 forks source link

Support for PHP7 return types and scalar type hints #11

Closed pavelkouril closed 9 years ago

pavelkouril commented 9 years ago

This PR adds support for new PHP7 language syntax & features, namely return type declarations and scalar type hints for generated files.

This feature is mandatory for PHP7 support in nette/di - ie. support of using return type declaration (instead of annotations) in automatically generated factories.

Majkl578 commented 9 years ago

One special case is probably missing, returning/typehinting self (PHP does not dereference it automatically).

pavelkouril commented 9 years ago

Thanks for pointing out the self dereferencing, I totally forgot about that. :)

EDIT: It seems the "self" and "parent" types are already available in 5.x. Should it even be in the scope of this PR (since this one is about adding PHP7 features) or done in a separate one?

pavelkouril commented 9 years ago

One more thing up for discussion - should setting the return type via setter (or converting to string) be limited by PHP version? In the DI use case, I did the check it on caller's side, but maybe it should be solved here instead?

(I didn't solve it here initially because I wanted to be consistent with variadics implementation, which don't check for PHP version in setters and __toString too.)

dg commented 9 years ago

No, it should generate code for PHP 7 even in PHP 5.

dg commented 9 years ago

Can you squash it to single commit?

pavelkouril commented 9 years ago

Just squashed commits for the first time. I hope I did it correctly! :)

dg commented 9 years ago

What about commit message added support for PHP 7 type hints?

pavelkouril commented 9 years ago

It's not just typehints, but also the return type declarations - so what about added support for PHP 7 type hints and return types or Method, Parameter: added support for PHP 7 type hints and return type declarations (it seems that you usually use the classes names that were affected by change in the commit message)?

dg commented 9 years ago

OK.

(return type hint is subset of type hint)

dg commented 9 years ago

Great, thanks!