Issues

ZF-6996: Parameter descriptions are incorrectly parsed by Zend_Server_Reflection_Function_Abstract _reflect() regular expression

Description

Zend_Server_Reflection_Function_Abstract, line 296:



This regular expression is to extract the parameter name and description from a parameter definition comment:

The part that scans for a variable name, ``` I.e. "dollar sign followed by one or more characters that are not - not whitespace" must read "dollar sign followed by one or more characters that are not whitespace"

Comments

Actually, the regex means "dollar sign followed by the beginning of a line followed by one or more characters that are not whitespace".

A circumflex outside of a character class (square brackets) means the beginning of a line, whereas a circumflex as the first character in a character class means that the character does not match any of the characters in the character class.

The part that scans for a variable name,

(\$^\S+)

should instead read

(\$\S+)

i.e. just remove the extraneous circumflex

Actually, I just discovered that a circumflex used outside of a character class is an assertion which is true only if the current matching point is at the start of the subject string, which does not necessarily imply the beginning of a line.

[http://php.net/manual/en/…]

Uploading patch previously uploaded to ZF-7344, which is a duplicate of this issue.

I was affected by this too, and came to exactly the same patch before finding this bug. It would be great if this could be fixed! :)

Fixed on trunk and 1.10 release branch.

This patch crashes Zend_Json tests:


# svn up -r 20618 library/Zend/Server/Reflection
U    library/Zend/Server/Reflection/Function/Abstract.php
Updated to revision 20618.

# php tests/Zend/Json/AllTests.php
PHPUnit 3.4.5 by Sebastian Bergmann.

........EEEEE..........E....................................  60 / 141
............................................................ 120 / 141
.....................

Time: 0 seconds, Memory: 13.25Mb

There were 6 errors:

1) Zend_Json_ServerTest::testShouldBeAbleToBindClassToServer
Undefined offset: 1

/home/mabe/workspace/zf-trunk/library/Zend/Server/Reflection/Function/Abstract.php:240
/home/mabe/workspace/zf-trunk/library/Zend/Server/Reflection/Function/Abstract.php:354
/home/mabe/workspace/zf-trunk/library/Zend/Server/Reflection/Method.php:83
/home/mabe/workspace/zf-trunk/library/Zend/Server/Reflection/Class.php:90
/home/mabe/workspace/zf-trunk/library/Zend/Server/Reflection.php:76
/home/mabe/workspace/zf-trunk/library/Zend/Json/Server.php:151
/home/mabe/workspace/zf-trunk/tests/Zend/Json/ServerTest.php:98
/home/mabe/workspace/zf-trunk/tests/Zend/Json/AllTests.php:45
/home/mabe/workspace/zf-trunk/tests/Zend/Json/AllTests.php:61

2) Zend_Json_ServerTest::testBindingClassToServerShouldRegisterAllPublicMethods
Undefined offset: 1

/home/mabe/workspace/zf-trunk/library/Zend/Server/Reflection/Function/Abstract.php:240
/home/mabe/workspace/zf-trunk/library/Zend/Server/Reflection/Function/Abstract.php:354
/home/mabe/workspace/zf-trunk/library/Zend/Server/Reflection/Method.php:83
/home/mabe/workspace/zf-trunk/library/Zend/Server/Reflection/Class.php:90
/home/mabe/workspace/zf-trunk/library/Zend/Server/Reflection.php:76
/home/mabe/workspace/zf-trunk/library/Zend/Json/Server.php:151
/home/mabe/workspace/zf-trunk/tests/Zend/Json/ServerTest.php:105
/home/mabe/workspace/zf-trunk/tests/Zend/Json/AllTests.php:45
/home/mabe/workspace/zf-trunk/tests/Zend/Json/AllTests.php:61

3) Zend_Json_ServerTest::testShouldBeAbleToBindObjectToServer
Undefined offset: 1

/home/mabe/workspace/zf-trunk/library/Zend/Server/Reflection/Function/Abstract.php:240
/home/mabe/workspace/zf-trunk/library/Zend/Server/Reflection/Function/Abstract.php:354
/home/mabe/workspace/zf-trunk/library/Zend/Server/Reflection/Method.php:83
/home/mabe/workspace/zf-trunk/library/Zend/Server/Reflection/Class.php:90
/home/mabe/workspace/zf-trunk/library/Zend/Server/Reflection.php:76
/home/mabe/workspace/zf-trunk/library/Zend/Json/Server.php:151
/home/mabe/workspace/zf-trunk/tests/Zend/Json/ServerTest.php:119
/home/mabe/workspace/zf-trunk/tests/Zend/Json/AllTests.php:45
/home/mabe/workspace/zf-trunk/tests/Zend/Json/AllTests.php:61

4) Zend_Json_ServerTest::testBindingObjectToServerShouldRegisterAllPublicMethods
Undefined offset: 1

/home/mabe/workspace/zf-trunk/library/Zend/Server/Reflection/Function/Abstract.php:240
/home/mabe/workspace/zf-trunk/library/Zend/Server/Reflection/Function/Abstract.php:354
/home/mabe/workspace/zf-trunk/library/Zend/Server/Reflection/Method.php:83
/home/mabe/workspace/zf-trunk/library/Zend/Server/Reflection/Class.php:90
/home/mabe/workspace/zf-trunk/library/Zend/Server/Reflection.php:76
/home/mabe/workspace/zf-trunk/library/Zend/Json/Server.php:151
/home/mabe/workspace/zf-trunk/tests/Zend/Json/ServerTest.php:127
/home/mabe/workspace/zf-trunk/tests/Zend/Json/AllTests.php:45
/home/mabe/workspace/zf-trunk/tests/Zend/Json/AllTests.php:61

5) Zend_Json_ServerTest::testShouldBeAbleToBindMultipleClassesAndObjectsToServer
Undefined offset: 1

/home/mabe/workspace/zf-trunk/library/Zend/Server/Reflection/Function/Abstract.php:240
/home/mabe/workspace/zf-trunk/library/Zend/Server/Reflection/Function/Abstract.php:354
/home/mabe/workspace/zf-trunk/library/Zend/Server/Reflection/Method.php:83
/home/mabe/workspace/zf-trunk/library/Zend/Server/Reflection/Class.php:90
/home/mabe/workspace/zf-trunk/library/Zend/Server/Reflection.php:76
/home/mabe/workspace/zf-trunk/library/Zend/Json/Server.php:151
/home/mabe/workspace/zf-trunk/tests/Zend/Json/ServerTest.php:140
/home/mabe/workspace/zf-trunk/tests/Zend/Json/AllTests.php:45
/home/mabe/workspace/zf-trunk/tests/Zend/Json/AllTests.php:61

6) Zend_Json_ServerTest::testSmdObjectRetrievedFromServerShouldReflectServerState
Undefined offset: 1

/home/mabe/workspace/zf-trunk/library/Zend/Server/Reflection/Function/Abstract.php:240
/home/mabe/workspace/zf-trunk/library/Zend/Server/Reflection/Function/Abstract.php:354
/home/mabe/workspace/zf-trunk/library/Zend/Server/Reflection/Method.php:83
/home/mabe/workspace/zf-trunk/library/Zend/Server/Reflection/Class.php:90
/home/mabe/workspace/zf-trunk/library/Zend/Server/Reflection.php:76
/home/mabe/workspace/zf-trunk/library/Zend/Json/Server.php:151
/home/mabe/workspace/zf-trunk/tests/Zend/Json/ServerTest.php:240
/home/mabe/workspace/zf-trunk/tests/Zend/Json/AllTests.php:45
/home/mabe/workspace/zf-trunk/tests/Zend/Json/AllTests.php:61

FAILURES!
Tests: 141, Assertions: 561, Errors: 6.

# svn up -r 20617 library/Zend/Server/Reflection
U    library/Zend/Server/Reflection/Function/Abstract.php
Updated to revision 20617.

# php tests/Zend/Json/AllTests.php
PHPUnit 3.4.5 by Sebastian Bergmann.

............................................................  60 / 141
............................................................ 120 / 141
.....................

Time: 0 seconds, Memory: 14.50Mb

OK (141 tests, 619 assertions)

Fixed in trunk and 1.10 release branch. Fixing this issue exposed another issue, basically, and this is now resolved.