Jump to content

phpDoc can't parse anonymous functions


NotionCommotion

Recommended Posts

When using the phpDoc PHAR to parse the following file, it returns Parse Error: Syntax error, unexpected '(' on line 16  No summary was found for this file, and doesn't include the file.  The specific script which triggers the error is ($this->prototype)().

I am using the PHAR listed on https://www.phpdoc.org/ which appears to be the same as https://github.com/phpDocumentor/phpDocumentor2/releases/download/v2.9.0/phpDocumentor.phar, and am running PHP 7.1.26.

Any guess why I am getting this error?  Recommended workarounds?  As a hack, I am thinking of adding an ignored function or class who's only missing is to invoke the anonymous function.

I've also tried using the PHAR at https://github.com/phpDocumentor/phpDocumentor2/releases/tag/v3.0.0-alpha.3, and while I don't get this error, I don't get any output.  I first tried it without downloading the public key but got ssl errors.  Is there more to in than just locating the two files in the same directory?

Thanks

<?php
/**
* My Summary.
*
* My Description.
*/
class Foo
{
    private $prototype;

    public function __construct() {
        $this->prototype=function(){ return 'prototype';};
    }

    public function getPrototype() {
        $prototype=($this->prototype)();
        return $prototype;
    }

}
[michael@devserver test]$ php /usr/share/phar/phpDocumentor.phar -d ./phpDocDir -t ./phpDocTarget
Collecting files .. OK
Initializing parser .. OK
Parsing files
Parsing /var/www/public/test/phpDocDir/testphpdocs.php
Parse Error: Syntax error, unexpected '(' on line 16  No summary was found for this file
Storing cache in "/var/www/public/test/phpDocTarget" .. OK
Load cache                                                         ..    0.001s
Preparing template "clean"                                         ..    0.011s
Preparing 17 transformations                                       ..    0.000s
Build "elements" index                                             ..    0.000s
Replace textual FQCNs with object aliases                          ..    0.000s
Resolve @link and @see tags in descriptions                        ..    0.000s
Enriches inline example tags with their sources                    ..    0.000s
Build "packages" index                                             ..    0.000s
Build "namespaces" index and add namespaces to "elements"          ..    0.000s
Collect all markers embedded in tags                               ..    0.000s
Transform analyzed project into artifacts                          ..
Applying 17 transformations
  Initialize writer "phpDocumentor\Plugin\Core\Transformer\Writer\FileIo"
  Initialize writer "phpDocumentor\Plugin\Twig\Writer\Twig"
  Initialize writer "phpDocumentor\Plugin\Graphs\Writer\Graph"
  Execute transformation using writer "FileIo"
  Execute transformation using writer "FileIo"
  Execute transformation using writer "FileIo"
  Execute transformation using writer "FileIo"
  Execute transformation using writer "FileIo"
  Execute transformation using writer "twig"
  Execute transformation using writer "twig"
  Execute transformation using writer "twig"
  Execute transformation using writer "twig"
  Execute transformation using writer "twig"
  Execute transformation using writer "twig"
  Execute transformation using writer "twig"
  Execute transformation using writer "twig"
  Execute transformation using writer "twig"
  Execute transformation using writer "twig"
  Execute transformation using writer "twig"
  Execute transformation using writer "Graph"
   0.073s
Analyze results and write report to log                            ..    0.000s
[michael@devserver test]$

 

Link to comment
Share on other sites

1 hour ago, requinix said:

Is phpDoc using its own PHP code parser? Because that syntax was valid. Just as valid as the one you have now (though you don't need that first pair of parentheses).

Not sure.  How could one tell?

Running into more quirks.  Do you use it or something else?

PS.  Yes, the first pair of parentheses are carryover from when I was using $this->myclosure.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.