ZF2-110: Zend\Code\DocBlockScanner doesn't recognize anymore tags without values

Issue Type: Bug Created: 2011-12-05T17:41:21.000+0000 Last Updated: 2012-10-08T20:15:37.000+0000 Status: Closed Fix version(s): Reporter: Massimiliano Torromeo (mtorromeo) Assignee: Maks 3w (maks3w) Tags: - Zend\Code\Scanner

  • reflection

Related issues: Attachments:


Component: Zend\Code (not listed)

The DocBlockScanner doesn't parse anymore tagnames wihout values such as this:

/** * @mytag */

They could be useful to tag code elements with custom tags as I was doing in zf 2.0 dev2


Posted by Adam Lundrigan (adamlundrigan) on 2012-02-23T17:44:45.000+0000

I believe this issue has been rectified already. I ran this unit test against Zend\Code\Scanner\DocBlockScanner:

<pre class="highlight">
 * @group ZF2-110
public function testDocBlockScannerParsesTagsWithNoValuesProperly()
    $docComment = <<getTags();
    $this->assertCount(1, $tags);
    $this->assertArrayHasKey('name', $tags[0]);
    $this->assertEquals('@mytag', $tags[0]['name']);
    $this->assertArrayHasKey('value', $tags[0]);
    $this->assertEquals('', $tags[0]['value']);

And it passed. I've issued a PR ( to get this test added to the ZF2 test suite.

Posted by Massimiliano Torromeo (mtorromeo) on 2012-02-23T21:30:13.000+0000

It seems I was wrong thinking that the problem was simply about tags without values. I still couldn't get my tags recognized with latest master and I found out that the issue was caused by a bug in the docblock cleaning function.

The regular expression used with single quotes failed to recognize tabs (\t) and also the cleaned docblock was not passed to the scanner.

Here is the fix:

<pre class="literal">
diff --git a/library/Zend/Code/Reflection/DocBlockReflection.php b/library/Zend/Code/Reflection/DocBlockReflection.php
index 564ce62..63c35d4 100644
--- a/library/Zend/Code/Reflection/DocBlockReflection.php
+++ b/library/Zend/Code/Reflection/DocBlockReflection.php
@@ -259,10 +259,10 @@ class DocBlockReflection implements Reflection
         $docComment = $this->docComment; // localize variable

         // create a clean docComment
-        $this->cleanDocComment = preg_replace('#[ \t]*(?:\/\*\*|\*\/|\*)?[ ]{0,1}(.*)?#', '$1', $docComment);
+        $this->cleanDocComment = preg_replace("#[ \t]*(?:\/\*\*|\*\/|\*)?[ ]{0,1}(.*)?#", '$1', $docComment);
         $this->cleanDocComment = ltrim($this->cleanDocComment, "\r\n"); // @todo should be changed to remove first and last empty line

-        $scanner = new DocBlockScanner($docComment);
+        $scanner = new DocBlockScanner($this->cleanDocComment);
         $this->shortDescription = ltrim($scanner->getShortDescription());
         $this->longDescription  = ltrim($scanner->getLongDescription());
         foreach ($scanner->getTags() as $tag) {

Posted by Maks 3w (maks3w) on 2012-05-14T16:09:44.000+0000

Hi Massimiliano,

You can send a Pull Request in Github with your patch. Anyway I tried to proposal but break some tests.


Posted by Ralph Schindler (ralph) on 2012-10-08T20:15:37.000+0000

This issue has been closed on Jira and moved to GitHub for issue tracking. To continue following the resolution of this issues, please visit:

Have you found an issue?

See the Overview section for more details.


© 2006-2016 by Zend, a Rogue Wave Company. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.