]> granicus.if.org Git - php/commitdiff
Fix bug #71767
authorGrigorii Sokolik <g.sokolik@delivery-club.ru>
Fri, 11 Mar 2016 16:28:45 +0000 (19:28 +0300)
committerNikita Popov <nikic@php.net>
Fri, 11 Mar 2016 21:27:48 +0000 (22:27 +0100)
NEWS
Zend/tests/grammar/regression_004.phpt
Zend/zend_language_parser.y
ext/reflection/tests/bug71767.phpt [new file with mode: 0644]

diff --git a/NEWS b/NEWS
index 1f9f3ebf9bc5182ff91eef3c1da3d3a1a722c282..bf9223b6f61bdbe0efd28295c309e1782529c7e7 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -23,6 +23,8 @@ PHP                                                                        NEWS
   . Fixed bug #71575 (ISO C does not allow extra ‘;’ outside of a function).
     (asgrim)
   . Fixed bug #71724 (yield from does not count EOLs). (Nikita)
+  . Fixed bug #71767 (ReflectionMethod::getDocComment returns the wrong
+    comment). (Grigorii Sokolik)
 
 - Curl:
   . Fixed bug #71694 (Support constant CURLM_ADDED_ALREADY). (mpyw)
index e95674d8c989e2c0fcecb416be87c141fc16ce30..edb32032ea56ff76e7d55e95e0dc1a87e8339823 100644 (file)
@@ -12,4 +12,4 @@ class Obj
 function echo(){} // not valid
 
 --EXPECTF--
-Parse error: syntax error, unexpected 'echo' (T_ECHO), expecting identifier (T_STRING) or '(' in %s on line 9
+Parse error: syntax error, unexpected 'echo' (T_ECHO), expecting %s in %s on line 9
index 49027b787e7f72b6d434f7acc2c8d4fcc7c14e93..804ed37473b4d846fb7db8770534258ccf417222 100644 (file)
@@ -473,10 +473,10 @@ unset_variable:
 ;
 
 function_declaration_statement:
-       function returns_ref T_STRING '(' parameter_list ')' return_type
-       backup_doc_comment '{' inner_statement_list '}'
-               { $$ = zend_ast_create_decl(ZEND_AST_FUNC_DECL, $2, $1, $8,
-                     zend_ast_get_str($3), $5, NULL, $10, $7); }
+       function returns_ref T_STRING backup_doc_comment '(' parameter_list ')' return_type
+       '{' inner_statement_list '}'
+               { $$ = zend_ast_create_decl(ZEND_AST_FUNC_DECL, $2, $1, $4,
+                     zend_ast_get_str($3), $6, NULL, $10, $8); }
 ;
 
 is_reference:
@@ -705,10 +705,10 @@ class_statement:
                        { $$ = $2; RESET_DOC_COMMENT(); }
        |       T_USE name_list trait_adaptations
                        { $$ = zend_ast_create(ZEND_AST_USE_TRAIT, $2, $3); }
-       |       method_modifiers function returns_ref identifier '(' parameter_list ')'
-               return_type backup_doc_comment method_body
-                       { $$ = zend_ast_create_decl(ZEND_AST_METHOD, $3 | $1, $2, $9,
-                                 zend_ast_get_str($4), $6, NULL, $10, $8); }
+       |       method_modifiers function returns_ref identifier backup_doc_comment '(' parameter_list ')'
+               return_type method_body
+                       { $$ = zend_ast_create_decl(ZEND_AST_METHOD, $3 | $1, $2, $5,
+                                 zend_ast_get_str($4), $7, NULL, $10, $9); }
 ;
 
 name_list:
@@ -959,16 +959,16 @@ expr_without_variable:
        |       T_YIELD expr { $$ = zend_ast_create(ZEND_AST_YIELD, $2, NULL); }
        |       T_YIELD expr T_DOUBLE_ARROW expr { $$ = zend_ast_create(ZEND_AST_YIELD, $4, $2); }
        |       T_YIELD_FROM expr { $$ = zend_ast_create(ZEND_AST_YIELD_FROM, $2); }
-       |       function returns_ref '(' parameter_list ')' lexical_vars return_type
-               backup_doc_comment '{' inner_statement_list '}'
-                       { $$ = zend_ast_create_decl(ZEND_AST_CLOSURE, $2, $1, $8,
+       |       function returns_ref backup_doc_comment '(' parameter_list ')' lexical_vars return_type
+               '{' inner_statement_list '}'
+                       { $$ = zend_ast_create_decl(ZEND_AST_CLOSURE, $2, $1, $3,
                                  zend_string_init("{closure}", sizeof("{closure}") - 1, 0),
-                             $4, $6, $10, $7); }
-       |       T_STATIC function returns_ref '(' parameter_list ')' lexical_vars
-               return_type backup_doc_comment '{' inner_statement_list '}'
-                       { $$ = zend_ast_create_decl(ZEND_AST_CLOSURE, $3 | ZEND_ACC_STATIC, $2, $9,
+                             $5, $7, $10, $8); }
+       |       T_STATIC function returns_ref backup_doc_comment '(' parameter_list ')' lexical_vars
+               return_type '{' inner_statement_list '}'
+                       { $$ = zend_ast_create_decl(ZEND_AST_CLOSURE, $3 | ZEND_ACC_STATIC, $2, $4,
                              zend_string_init("{closure}", sizeof("{closure}") - 1, 0),
-                             $5, $7, $11, $8); }
+                             $6, $8, $11, $9); }
 ;
 
 function:
diff --git a/ext/reflection/tests/bug71767.phpt b/ext/reflection/tests/bug71767.phpt
new file mode 100644 (file)
index 0000000..8c4059a
--- /dev/null
@@ -0,0 +1,44 @@
+--TEST--
+Bug #71767 (ReflectionMethod::getDocComment returns the wrong comment)
+--FILE--
+<?php
+
+/** Correct docblock */
+function foo(
+    /** wrong docblock */
+    $arg
+) {
+}
+
+class Foo {
+    /** Correct docblock */
+    public function bar(
+        /** wrong docblock */
+        $arg
+    ) {
+        
+    }
+}
+
+/** Correct docblock */
+$func = function(
+    /** wrong docblock */
+    $arg
+) {
+};
+
+$reflectionFunction = new ReflectionFunction('foo');
+$reflectionClass = new ReflectionClass(Foo::class);
+$reflectionClosure = new ReflectionFunction($func);
+
+echo $reflectionFunction->getDocComment() . PHP_EOL;
+echo $reflectionClass->getMethod('bar')->getDocComment() . PHP_EOL;
+echo $reflectionClosure->getDocComment() . PHP_EOL;
+
+echo "Done\n";
+?>
+--EXPECTF--
+/** Correct docblock */
+/** Correct docblock */
+/** Correct docblock */
+Done