Skip to content
This repository has been archived by the owner on Jan 29, 2020. It is now read-only.

PHP 7.1 support #87

Merged
merged 60 commits into from
Oct 24, 2016
Merged

Conversation

Ocramius
Copy link
Member

@Ocramius Ocramius commented Aug 19, 2016

This PR introduces initial support for PHP 7.1 nullable (? syntax) return and parameter hints, as well as void return hint.

Implements #84
Implements #85

This last change can probably be reversed, since we don't really use `getType()` besides for testing, while consumers may actually be doing that...~~~ (fixed, BC retained)

TODOs:
- [x] code review (ping @trowski, since you may want to adjust implementation on this)
- [x] code review (ping @nikic, since you had the idea of just dropping `ReflectionType#__toString()`)
- [x] figure out how to make this work both on 7.1 and on 7.0 (currently works only on 7.1)
- [x] figure out why PHP throws `'Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 4755801206603911168 bytes) in /Users/ocramius/Documents/Projects/zend/zend-code/vendor/sebastian/global-state/src/Snapshot.php on line 329'` and `'Process finished with exit code 139 (interrupted by signal 11: SIGSEGV)'` when dealing with `(string)` casts of a `ReflectionType` representing a `?string` type

Note: changes will need to be reflected into:
- https://github.com/doctrine/common/issues/731
- https://github.com/Ocramius/ProxyManager/pull/327
- https://github.com/Ocramius/ProxyManager/issues/314

@Ocramius
Copy link
Member Author

@weierophinney can we drop PHP 5 at some point?

[NullableHintsClass::class, 'callableParameter', 'foo', '?callable'],
[NullableHintsClass::class, 'intParameter', 'foo', '?int'],
[NullableHintsClass::class, 'floatParameter', 'foo', '?float'],
// [NullableHintsClass::class, 'stringParameter', 'foo', '?string'],
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Enabling this makes the test suite fail in the most weird ways (see issue description TODOs) /cc @trowski @nikic

@weierophinney
Copy link
Member

can we drop PHP 5 at some point?

Eventually, but not yet. 5.6 is still supported. Once that goes off active support, we can do a new minor version that bumps minimum to a v7 release.

@Ocramius
Copy link
Member Author

Eventually, but not yet. 5.6 is still supported. Once that goes off active support, we can do a new minor version that bumps minimum to a v7 release.

I'll start ticking off the days.

@RalfEggert
Copy link
Contributor

Please don't drop the PHP 5.6 support too early. There are a lot of projects out there which won't be merged to PHP 7.x so quickly.

I would favour a new major release rather than a new minor release. Should be 4.x then to drop PHP 5.6 support. People tend to configure their composer.json files like this:

    "zendframework/zend-code": "^3.0",

and not like this:

    "zendframework/zend-code": "^3.0.0",

Jm2c

@Ocramius
Copy link
Member Author

@RalfEggert this targets 4.0

@RalfEggert
Copy link
Contributor

Great! then I misunderstood Matthews comment...

@djmattyg007
Copy link
Contributor

What about support for these things in the Scanner classes?

@Ocramius
Copy link
Member Author

@djmattyg007 didn't check them at all, sorry.

@djmattyg007
Copy link
Contributor

So is it safe to say at this point that the Scanner classes are no longer maintained?

@Ocramius
Copy link
Member Author

No, i simply didn't t look at them, nor will do so in this PR. You can work on them basing your work on the test assets in this PR, if you want.

@Ocramius Ocramius changed the title Feature/php 7 1 support PHP 7.1 support Sep 13, 2016
[NullNullableDefaultHintsClass::class, 'callableParameter', 'foo', '?callable'],
[NullNullableDefaultHintsClass::class, 'intParameter', 'foo', '?int'],
[NullNullableDefaultHintsClass::class, 'floatParameter', 'foo', '?float'],
// [NullNullableDefaultHintsClass::class, 'stringParameter', 'foo', '?string'],
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here - to be tried again with 7.1-beta

@nikic
Copy link

nikic commented Sep 13, 2016

Are you still seeing the "allowed memory size" issue on the RC1 build?

@Ocramius Ocramius removed the BC Break label Sep 13, 2016
@Ocramius Ocramius modified the milestones: 3.1.0, 4.0.0 Sep 13, 2016
@Ocramius
Copy link
Member Author

Ocramius commented Sep 13, 2016

I think that this is ready for review/merge.

Works on 5.6, 7.0, 7.1. Dropped 5.6 5.5 because I'm a sneaky bastard.

@weierophinney
Copy link
Member

Dropped 5.6 because I'm a sneaky bastard.

You mean you dropped 5.5. Which is perfectly acceptable for the next minor release. 😄

@Ocramius
Copy link
Member Author

Yep, typo, sorry :-)

@Ocramius
Copy link
Member Author

Are you still seeing the "allowed memory size" issue on the RC1 build?

@nikic that's gone, thanks! :-)

* @var string[]
*
* @link http://php.net/manual/en/functions.arguments.php#functions.arguments.type-declaration
*/
private static $internalPhpTypes = ['int', 'float', 'string', 'bool', 'array', 'callable'];
private static $internalPhpTypes = ['void', 'int', 'float', 'string', 'bool', 'array', 'callable'];
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about iterable?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wait, that passed? :O

Copy link
Member Author

@Ocramius Ocramius Sep 13, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alright, to be added (as separate test asset, since iterable can be a class/interface in 5.6 and 7.0)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Definitely want iterable as part of the final changes. 😄

Copy link
Member

@weierophinney weierophinney left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks sane! The primary concerns I have are noted in other review comments, but include:

  • Should static and/or $this be considered for type hint generation if generating types from docblocks?
  • License docblocks in test assets.
  • Adding support for the iterable type.

Thanks, @Ocramius !

- php: 5.6
env:
- EXECUTE_CS_CHECK=true
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's move this into the PHP 7 target, so that we can get results earlier, please. (That's what we've done in other components as well.)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just verified: can't do, since the lock file was generated with 5.x deps

*
* @return string
*/
private static function expandLiteralType($literalReturnType, ReflectionMethod $methodReflection)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Am I reading this correctly in that it pulls the type from reflecting the docblock in this case? If so, should it also consider static and $this? (If it's strictly from declared return type, ignore.)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If so, should it also consider static and $this? (If it's strictly from declared return type, ignore.)

static is not a valid type hint (for good reasons). static is used when resolving methods to call inside an instance, but it is not possible to use it as a hint due to its natural non-LSP-compliance.

$this is not a type

In general, reflecting from docblocks is now a deprecated feature (there are explicit tests that verify that docblocks aren't used for reflecting anymore)

*
* @return string
*/
private static function expandLiteralParameterType($literalParameterType, ReflectionParameter $reflectionParameter)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment as with MethodGenerator.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment as with MethodGenerator

[ClassTypeHintedClass::class, 'classParameter', 'foo', '\\' . ClassTypeHintedClass::class],
[ClassTypeHintedClass::class, 'otherClassParameter', 'foo', '\\' . InternalHintsClass::class],
[ClassTypeHintedClass::class, 'closureParameter', 'foo', '\\' . \Closure::class],
[ClassTypeHintedClass::class, 'importedClosureParameter', 'foo', '\\' . \Closure::class],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Out of curiousity... why are the Null* cases prior to the others, which are all in alpha order by class name otherwise? (I ask, because I thought at first you'd removed the ClassTypeHintedClass cases until I discovered they'd been shifted down...)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added the assets in the order in which I copied them and adapted them. That's why they don't appear at the end of the list

@@ -0,0 +1,38 @@
<?php

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

EmptyClass includes the license docblock, but this and those following do not; should they? or are they used for comparison purposes?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Docblocks are not important here, and may actually confuse the reader of the assets, so maybe I should remove it from EmptyClass as well.

@Ocramius
Copy link
Member Author

Ocramius commented Sep 16, 2016

@weierophinney implemented iterable support, removed useless docblock on EmptyClass

@Ocramius
Copy link
Member Author

@weierophinney this is ready for merge :shipit:

@Ocramius Ocramius dismissed weierophinney’s stale review October 24, 2016 13:03

review completed - discussed directly on IRC with @weierophinney

@Ocramius
Copy link
Member Author

Merging. The failure is caused by a CS check that is fixed in master, and will be fixed here when merging develop into master.

@Ocramius Ocramius self-assigned this Oct 24, 2016
@Ocramius Ocramius merged commit 3449c7c into zendframework:develop Oct 24, 2016
@Ocramius Ocramius deleted the feature/php-7-1-support branch October 24, 2016 13:06
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants