Zend Framework

Parameter descriptions are incorrectly parsed by Zend_Server_Reflection_Function_Abstract _reflect() regular expression

Details

  • Type: Bug Bug
  • Status: Resolved Resolved
  • Priority: Minor Minor
  • Resolution: Fixed
  • Affects Version/s: 1.7.6, 1.7.7, 1.7.8, 1.8.0, 1.8.1, 1.8.2
  • Fix Version/s: 1.10.0
  • Component/s: Zend_Server_Reflection
  • Labels:
    None

Description

Zend_Server_Reflection_Function_Abstract, line 296:

if (preg_match_all('/@param\s+\S+\s+(\$^\S+)\s+(.*?)(@|\*\/)/s', $docBlock, $matches))

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

@param paramType $paramName Parameter Description

The part that scans for a variable name,

(\$^\S+)
, should read
(\$^\s+)

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"

Issue Links

Activity

Hide
Stephen Leavitt added a comment -

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

Show
Stephen Leavitt added a comment - 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
Hide
Stephen Leavitt added a comment -

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://www.php.net/manual/en/regexp.reference.circudollar.php

Show
Stephen Leavitt added a comment - 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://www.php.net/manual/en/regexp.reference.circudollar.php
Hide
Stephen Leavitt added a comment -

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

Show
Stephen Leavitt added a comment - Uploading patch previously uploaded to ZF-7344, which is a duplicate of this issue.
Hide
Penny Leach added a comment -

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!

Show
Penny Leach added a comment - 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!
Hide
Matthew Weier O'Phinney added a comment -

Fixed on trunk and 1.10 release branch.

Show
Matthew Weier O'Phinney added a comment - Fixed on trunk and 1.10 release branch.
Hide
Marc Bennewitz (private) added a comment -

This patch crashes Zend_Json tests:

r20618
# 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.
r20617
# 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)
Show
Marc Bennewitz (private) added a comment - This patch crashes Zend_Json tests:
r20618
# 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.
r20617
# 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)
Hide
Matthew Weier O'Phinney added a comment -

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

Show
Matthew Weier O'Phinney added a comment - Fixed in trunk and 1.10 release branch. Fixing this issue exposed another issue, basically, and this is now resolved.

People

Vote (3)
Watch (2)

Dates

  • Created:
    Updated:
    Resolved: