-
Notifications
You must be signed in to change notification settings - Fork 79
[3.0] #29 - PHP7 compliance #30
[3.0] #29 - PHP7 compliance #30
Conversation
@@ -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(), |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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. 😄
👏 this is great stuff. I'm so looking forward to this! |
Note: I re-added support for PHP 5.x, although it's nasty and it will produce different results with |
} | ||
|
||
/** | ||
* @param boolean $returnsReference |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@param bool for consistency
…names - refactored tests
…ce` class names
…s with PHP7's `ReflectionParameter#getType()`
…pe`, adding tests for `detectType`
@weierophinney this is all set and ready to go :-)
|
👍 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. |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will add an example
@Ocramius This looks great! I have a few requests for clarifications above, as well as some questions about docblock-based typehints. |
…ing PHP5-compliant code
…MethodGenerator::fromReflection()` is required
@weierophinney applied changes according to your review, thanks! |
Final comments:
Excellent work, Marco! With those minor changes, I'll merge, and prepare the 3.0 tag! |
…y, as part of the doctree
@Ocramius Perfect; thanks! |
[3.0] #29 - PHP7 compliance
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).BC Breaks
This patch introduces a couple of BC Breaks:
Zend\Code\Reflection\ParameterReflection#getType()
required a rename, since it clashes with the newly introducedReflectionParameter#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 considerint
,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 requiredZend\Code\Generator\ParameterGenerator#$type
is now aZend\Code\Generator\TypeGenerator
(stringable, but not a string)protected static Zend\Code\Generator\ParameterGenerator::$simple
was droppedTODO
Notes
Commits are not to be squashed, as I'm detailing progress in each commit, especially around edge cases.