ZF-8566: Zend_Server_Reflection_Function_Abstract parsing parameter description regex only matches every second description


Consider a doc block like this:

  * Short description
  * @param array $param1 Description 1
  * @param array $param2 Description 2
  * @param int $param3 Description 3
  * @param string $param4 Description 4
  * @return array return description

The regex used for parsing the descriptions of the parameters in the _reflect() function will only match "Description 1" and "Description 3", because with each match it already matches the @ of the next @param. Therefore it skips the following parameter description and continues with the one after that.

The fix is pretty simple: Just use a lookahead so that the @ isn't already part of the match and the regex machine will consider it for further matching (see patch attached).


This fix works.

For ZendFramework-1.10.8 here is a patch for the fix: The file in question is: library/Zend/Server/Reflection/Function/Abstract.php

--- Abstract.php 2010-11-10 17:08:37.000000000 -0700 +++ Abstract.php 2010-11-10 17:08:45.000000000 -0700 @@ -293,7 +293,7 @@ // Get param types and description if (preg_match_all('/@param\s+([^\s]+)/m', $docBlock, $matches)) { $paramTypesTmp = $matches[1]; - if (preg_match_all('/@param\s+\S+\s+(\$\S+)\s+(.?)(@|*\/)/s', $docBlock, $matches)) + if (preg_match_all('/@param\s+\S+\s+(\$\S+)\s+(.?)(?=@|*\/)/s', $docBlock, $matches)) { $paramDesc = $matches[2]; foreach ($paramDesc as $key => $value) {

fixed in r23317