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

[3.0] #29 - PHP7 compliance #30

Merged
merged 108 commits into from
Jan 13, 2016

Conversation

Ocramius
Copy link
Member

@Ocramius Ocramius commented Jan 3, 2016

This is a first draft that requires a look by @weierophinney.

See #29

Features

This patch introduces a few features that are very much required in order to use Zend\Code in PHP7 (currently generates broken garbage, which is what forced me to write the patch in first place).

  • by-ref method return support (ported from ProxyManager)
  • variadic support
  • scalar type hint support (this required a BC break, documented below)
  • return type hint support

BC Breaks

This patch introduces a couple of BC Breaks:

  • Zend\Code\Reflection\ParameterReflection#getType() required a rename, since it clashes with the newly introduced ReflectionParameter#getType()
  • Zend\Code\Generator\ParameterGenerator#setType() now expects users to pass in the type without prefixing it with \\
  • Zend\Code\Generator\ParameterGenerator#getType() now returns the types without the prefixing \\
  • Zend\Code\Generator\ParameterGenerator#generate() now generates types with a prefixing \\ when a class is given: all classes should be provided via fully qualified class name. Passing in a name prefixed with \\ is supported, but when asking for a type, a string without the prefixing \\ will be retrieved.
  • Zend\Code\Generator\ParameterGenerator now doesn't consider int, string, float, bool as special types, and doesn't omit them from generated signatures anymore. Note: while this is broken as heck, people may have relied on it, and the BC break is subtle, but required
  • Zend\Code\Generator\ParameterGenerator#$type is now a Zend\Code\Generator\TypeGenerator (stringable, but not a string)
  • protected static Zend\Code\Generator\ParameterGenerator::$simple was dropped

TODO

  • document BC breaks

Notes

Commits are not to be squashed, as I'm detailing progress in each commit, especially around edge cases.

@Ocramius Ocramius added this to the 3.0.0 milestone Jan 3, 2016
@Ocramius Ocramius changed the title [3.0] PHP7 compliance [3.0] #29 - PHP7 compliance Jan 3, 2016
@@ -135,7 +135,7 @@ public function getPrototype($format = FunctionReflection::PROTOTYPE_AS_ARRAY)
$parameters = $this->getParameters();
foreach ($parameters as $parameter) {
$prototype['arguments'][$parameter->getName()] = [
'type' => $parameter->getType(),
'type' => $parameter->detectType(),
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 am not sure why we have a getPrototype API: seems useless

Copy link
Member

Choose a reason for hiding this comment

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

@Ocramius — It's used by Zend\Server\Reflection, and thus the Zend\XmlRpc\Server, Zend\Json\Server, and Zend\Soap\Server implementations in order to provide the various possible method invocation combinations so that they can:

  • provide API usage
  • validate provided parameters when processing a request

We moved it out of Zend\Server\Reflection, IIRC. We could potentially move it back in, but I'd also argue it's a value-add for this component.

Copy link
Member Author

Choose a reason for hiding this comment

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

@weierophinney doesn't need to be moved out of the component, just out of this class, IMO (future change)

Copy link
Member

Choose a reason for hiding this comment

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

Maybe start a TODO for those future changes. 😄

@nilportugues
Copy link

👏 this is great stuff. I'm so looking forward to this!

@Ocramius
Copy link
Member Author

Ocramius commented Jan 4, 2016

Note: I re-added support for PHP 5.x, although it's nasty and it will produce different results with string, float, etc...

}

/**
* @param boolean $returnsReference
Copy link
Contributor

Choose a reason for hiding this comment

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

@param bool for consistency

@Ocramius
Copy link
Member Author

Ocramius commented Jan 5, 2016

@weierophinney this is all set and ready to go :-)

CHANGELOG.md and UPGRADE.md also provided.

@gianarb
Copy link

gianarb commented Jan 5, 2016

👍 Thanks for this effort!

In 3.x, this code will instead produce `"string $foo"`.
If you generate code that should run in PHP 5.x, it is advisable to strip
`string`, `int`, `float` and `bool` from type definitions passed to
`Zend\Code\ParameterGenerator` instances.
Copy link
Member

Choose a reason for hiding this comment

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

Can you indicate how one would do this, please?

Copy link
Member Author

Choose a reason for hiding this comment

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

Will add an example

@weierophinney
Copy link
Member

@Ocramius This looks great! I have a few requests for clarifications above, as well as some questions about docblock-based typehints.

@Ocramius
Copy link
Member Author

@weierophinney applied changes according to your review, thanks!

@weierophinney
Copy link
Member

Final comments:

  • Make the PHP requirement ^5.5 || ^7.0, for consistency with other components.
  • Update the branch alias for dev-develop to 3.0-dev.
  • Please create a "migration" guide in the documentation; you can crib a lot (most?) of it from your UPGRADE.md, but that way it can be part of a published manual as well.

Excellent work, Marco! With those minor changes, I'll merge, and prepare the 3.0 tag!

@weierophinney
Copy link
Member

@Ocramius Perfect; thanks!

@weierophinney weierophinney merged commit b464169 into zendframework:develop Jan 13, 2016
weierophinney added a commit that referenced this pull request Jan 13, 2016
weierophinney added a commit that referenced this pull request Jan 13, 2016
@Ocramius Ocramius deleted the feature/php7-compliance branch January 13, 2016 19:44
@Ocramius
Copy link
Member Author

glassplainbadger

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.

7 participants