It appears that nullable data types are not supported yet. I know this is a really new feature, I just wanted to get this out there.
Here is an example of something it can't parse:
public function getId(): ?int
{
return $this->id;
}
Here is the error that is thrown: Syntax error, unexpected '?'
Hello @nbrink91,
Unfortunately we have a backlog of items that we need to pick up for complete compatibility with the latest PHP versions. Thank you for making us aware of this issue and I have added it to the roadmap
Hello @mvriel ,
when will be a 2.9.1 release and a 3.0.0 release?
I also run into the problems which @nbrink91 mentioned and don't have a solution right now.
@thbergler when you don't care about bleeding etch stuff you could give #1888 a try. It will render documentation. But not all functionality is working and fully tested. Feel free to report issues when you are using that branch.
@jaapio does not work either.
I get the following error:
Parse Error: Syntax error, unexpected '?' on line 284 No summary was found for this file
In that case you will have to wait. I can't give you an date of a new release. Like @mvriel we have this on our backlog. With the highest prio. But we have limited resources. We are working on the project when there is time.
Interesting/bad side effect of this: Generated diagrams still draw the classes with nullable return values, but at completely wrong positions. In this example, it's the Color and Primitive classes
@webD97 I don't understand what you are trying to explain to me. Which version of php documentor did you use?
Is this still the case with the version in the develop branch?
Can I try this my self with your project?
I installed phpdocumentor using Composer with "dev-master" version. vendor/bin/phpdoc -V reports version 2.9.1.
My code can be found here. There's a helper script in /util to generate the documentation because I'm also using phpdoc-md, but that shouldn't matter. I created a custom template in docs/assets/template that generates XML output and a classes.svg graph as shown in my previous comment.
When running phpdoc, the files with nullable return values create errors like this:
Parsing /home/christian/Schreibtisch/chameleon/src/Colors/Color.php
Parse Error: Syntax error, unexpected '?' on line 36 No summary was found for this file
Every file/class that produces this error, is either drawn at a wrong position in the diagram (not in the right namespace) or it is not drawn at all. If you take a look at the diagram I posted before, you can see the following problems:
Color class is outside the global namespace, but it should be in Chameleon\ColorsChameleon\Primitives namespace is drawn twice (the one at the top only has the Primitive class in it, which should be placed in the "real" Chameleon\Primitives section below)Mask class is not drawn at all, it should be in Chameleon namespaceEdit: Seems like I didn't test the develop branch yet, so I'm trying it right now.
Edit#2: I can't run the current develop version at all. There are no parse errors anymore, but it fails with a TypeError later:
(...)
Replace textual FQCNs with object aliases .. [2017-09-15 07:27:25] phpDocumentor.ERROR: Uncaught Exception TypeError: "Argument 1 passed to phpDocumentor\Descriptor\Tag\BaseTypes\TypedAbstract::setTypes() must implement interface phpDocumentor\Reflection\Type or be null, instance of phpDocumentor\Descriptor\Collection given, called in /home/christian/Schreibtisch/chameleon/vendor/phpdocumentor/phpdocumentor/src/phpDocumentor/Compiler/Linker/Linker.php on line 183" at /home/christian/Schreibtisch/chameleon/vendor/phpdocumentor/phpdocumentor/src/phpDocumentor/Descriptor/Tag/BaseTypes/TypedAbstract.php line 33 {"exception":"[object] (TypeError(code: 0): Argument 1 passed to phpDocumentor\\Descriptor\\Tag\\BaseTypes\\TypedAbstract::setTypes() must implement interface phpDocumentor\\Reflection\\Type or be null, instance of phpDocumentor\\Descriptor\\Collection given, called in /home/christian/Schreibtisch/chameleon/vendor/phpdocumentor/phpdocumentor/src/phpDocumentor/Compiler/Linker/Linker.php on line 183 at /home/christian/Schreibtisch/chameleon/vendor/phpdocumentor/phpdocumentor/src/phpDocumentor/Descriptor/Tag/BaseTypes/TypedAbstract.php:33)"} []
Thanks for reporting I will have a look where this is coming from.
Please note that we do not have full support for php 7+ yet. That's work in progress.
I noticed that, just wanted to mention this side effect. Thanks for your effort!
For what it's worth, this appears to originate from PhpParser. Here is a stack trace:
PhpParser\Error: Syntax error, unexpected '?' on line 130 in ~/.composer/vendor/nikic/php-parser/lib/PhpParser/ParserAbstract.php:275
Stack trace:
#0 ~/.composer/vendor/phpdocumentor/reflection/src/phpDocumentor/Reflection/Traverser.php(52): PhpParser\ParserAbstract->parse('<?php\n/**\n *\n *...')
#1 ~/.composer/vendor/phpdocumentor/reflection/src/phpDocumentor/Reflection/FileReflector.php(163): phpDocumentor\Reflection\Traverser->traverse('<?php\n/**\n *\n *...')
#2 ~/.composer/vendor/phpdocumentor/phpdocumentor/src/phpDocumentor/Parser/File.php(66): phpDocumentor\Reflection\FileReflector->process()
#3 ~/.composer/vendor/phpdocumentor/phpdocumentor/src/phpDocumentor/Parser/Parser.php(359): phpDocumentor\Parser\File->parse('~/...', Object(phpDocumentor\Descriptor\ProjectDescriptorBuilder))
#4 ~/.composer/vendor/phpdocumentor/phpdocumentor/src/phpDocumentor/Parser/Parser.php(319): phpDocumentor\Parser\Parser->parseFileIntoDescriptor(Object(phpDocumentor\Descriptor\ProjectDescriptorBuilder), '~/...')
#5 ~/.composer/vendor/phpdocumentor/phpdocumentor/src/phpDocumentor/Parser/Command/Project/ParseCommand.php(224): phpDocumentor\Parser\Parser->parse(Object(phpDocumentor\Descriptor\ProjectDescriptorBuilder), Object(phpDocumentor\Fileset\Collection))
#6 ~/.composer/vendor/symfony/console/Command/Command.php(266): phpDocumentor\Parser\Command\Project\ParseCommand->execute(Object(Symfony\Component\Console\Input\ArrayInput), Object(phpDocumentor\Console\Output\Output))
#7 ~/.composer/vendor/phpdocumentor/phpdocumentor/src/phpDocumentor/Command/Project/RunCommand.php(260): Symfony\Component\Console\Command\Command->run(Object(Symfony\Component\Console\Input\ArrayInput), Object(phpDocumentor\Console\Output\Output))
#8 ~/.composer/vendor/symfony/console/Command/Command.php(266): phpDocumentor\Command\Project\RunCommand->execute(Object(phpDocumentor\Console\Input\ArgvInput), Object(phpDocumentor\Console\Output\Output))
#9 ~/.composer/vendor/symfony/console/Application.php(875): Symfony\Component\Console\Command\Command->run(Object(phpDocumentor\Console\Input\ArgvInput), Object(phpDocumentor\Console\Output\Output))
#10 ~/.composer/vendor/symfony/console/Application.php(204): Symfony\Component\Console\Application->doRunCommand(Object(phpDocumentor\Command\Project\RunCommand), Object(phpDocumentor\Console\Input\ArgvInput), Object(phpDocumentor\Console\Output\Output))
#11 ~/.composer/vendor/symfony/console/Application.php(122): Symfony\Component\Console\Application->doRun(Object(phpDocumentor\Console\Input\ArgvInput), Object(phpDocumentor\Console\Output\Output))
#12 ~/.composer/vendor/phpdocumentor/phpdocumentor/src/phpDocumentor/Application.php(183): Symfony\Component\Console\Application->run(Object(phpDocumentor\Console\Input\ArgvInput), Object(phpDocumentor\Console\Output\Output))
#13 ~/.composer/vendor/phpdocumentor/phpdocumentor/bin/phpdoc(24): phpDocumentor\Application->run()
#14 {main}Parse Error: Syntax error, unexpected '?' on line 130 No summary was found for this file
This appears related to phpdocumentor/reflection using nikic/php-parser: ^1.0 which maxes out at PHP 5.6.
Could the fix be as simple as requiring a later (7.1-capable) version of php-parser?
FWIW, using phpdocumentor dev-develop and applying the following patch should at least allow parsing to complete without errors:
diff --git a/src/phpDocumentor/Descriptor/Interfaces/PropertyInterface.php b/src/phpDocumentor/Descriptor/Interfaces/PropertyInterface.php
index 1c78297f..90beb882 100644
--- a/src/phpDocumentor/Descriptor/Interfaces/PropertyInterface.php
+++ b/src/phpDocumentor/Descriptor/Interfaces/PropertyInterface.php
@@ -58,7 +58,7 @@ interface PropertyInterface extends ElementInterface, TypeInterface
*
* @return void
*/
- public function setTypes(Type $types);
+ public function setTypes($types);
/**
* Returns the types associated with the value(s) for this property.
diff --git a/src/phpDocumentor/Descriptor/PropertyDescriptor.php b/src/phpDocumentor/Descriptor/PropertyDescriptor.php
index dbc4105c..f4cda887 100644
--- a/src/phpDocumentor/Descriptor/PropertyDescriptor.php
+++ b/src/phpDocumentor/Descriptor/PropertyDescriptor.php
@@ -91,7 +91,7 @@ class PropertyDescriptor extends DescriptorAbstract implements
/**
* {@inheritDoc}
*/
- public function setTypes(Type $types)
+ public function setTypes($types)
{
$this->types = $types;
}
diff --git a/src/phpDocumentor/Descriptor/Tag/BaseTypes/TypedAbstract.php b/src/phpDocumentor/Descriptor/Tag/BaseTypes/TypedAbstract.php
index 6c5f8d09..f31e9952 100644
--- a/src/phpDocumentor/Descriptor/Tag/BaseTypes/TypedAbstract.php
+++ b/src/phpDocumentor/Descriptor/Tag/BaseTypes/TypedAbstract.php
@@ -30,7 +30,7 @@ abstract class TypedAbstract extends TagDescriptor
*
* @return void
*/
- public function setTypes(Type $types = null)
+ public function setTypes($types = null)
{
$this->types = $types;
}
... but then it doesn't report failures, either. :-/
Thanks for reporting. The develop branch contains all latest development features of phpdocumentor. To support at least all files up to 7.2 syntax. We are not finished yet with all changes that are required to support all features of the new php 7+ features. We are aiming at a first alpha release that allows users to pars files up to 7.2. New features will be added afterwards.
I will try to keep you posted about our progress.
Today we released v3.0.0-alpha1. Which should just be able to process this kind of code.
I was not able to add an testcase for this yet. Therefor this issue is still open. Will close it when testcase is ready
Should be resolved now in the current develop branch. Pull the new docker image in a few minutes when it is build to check. This will be part of v3.0.0-alpha2
Most helpful comment
Hello @nbrink91,
Unfortunately we have a backlog of items that we need to pick up for complete compatibility with the latest PHP versions. Thank you for making us aware of this issue and I have added it to the roadmap