php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #26456 Wrong results from Reflection-API getDocComment() when called via STDIN
Submitted: 2003-11-28 17:07 UTC Modified: 2005-06-07 20:12 UTC
Votes:1
Avg. Score:3.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:1 (100.0%)
From: schlueter at phpbar dot de Assigned:
Status: Closed Package: Scripting Engine problem
PHP Version: 5CVS-2004-03-15 OS: linux
Private report: No CVE-ID:
 [2003-11-28 17:07 UTC] schlueter at phpbar dot de
Description:
------------
While testing the examples from http://sitten-polizei.de/php/reflection_api/docs/language.reflection.html I found a (for me) unexpected beahvior with Reflection_Function::getDocComment() and Reflection_Method::getDocComment() the  when calling PHP on the command line without paramter and copying a test script into my shell window, so PHP can read it from STDIN. If I call the same script from a file or pipe (cat test.php | /opt/php5/bin/php) all seems to work.

Reproduce code:
---------------
Example 14-5 from http://sitten-polizei.de/php/reflection_api/docs/language.reflection.class.reflection_method.html

Expected result:
----------------
===> The user-defined final public static method 'increment' (which is a regular method)
     declared in -
     lines 13 to 17
     having the modifiers 261[final public static]
---> Documentation:
 '/**
       * Increment counter
       *
       * @final
       * @static
       * @access  public
       * @return  int
       */'
---> Invokation results in: int(1)

Actual result:
--------------
===> The user-defined final public static method 'increment' (which is a regular method)
     declared in /home/johannes/-
     lines 13 to 17
     having the modifiers 261[final public static]
---> Documentation:
 '
      final public static function increment)
final
       * @static
       * @access  public
       * @return  int
       */'
---> Invokation results in: int(1)

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2003-11-28 20:32 UTC] sniper@php.net
Please try using this CVS snapshot:

  http://snaps.php.net/php5-latest.tar.gz
 
For Windows:
 
  http://snaps.php.net/win32/php5-win32-latest.zip

..and show exactly HOW you run it when it doesn't work,



 [2003-11-29 09:15 UTC] schlueter at phpbar dot de
I've tested now with php5-200311291230 (simply ./configure without any paramters) and get the same results. And the exact way I'm runnig PHP ist this:

1. I'm opening a shell window
2. $ ./php [return]
3. I put the source into the clipboard
4. I paste it into the shell window
5. Ctrl+D
6. Wrong results (see original report) appear

I hope now it's clear how I'm doing it.
I've just tested it on another Linux machine: Same results...
 [2003-11-30 04:28 UTC] sniper@php.net
Thank you for the explanation. (I've never ever run scripts like this :). Verified..and here's short example script to test this:

<?php

  class Counter {
      private static $c = 0;

      /**
       * Increment counter
       *
       * @access  public
       * @return  int
       */
      function increment()
      {
          self::$c++;
          return self::$c;
      }
  }

  // Create an instance of the Reflection_Method class
  $method= new Reflection_Method('Counter', 'increment');

  // Print documentation comment
  echo "\n--------------------------------------------------\n";
  echo $method->getDocComment();
  echo "\n--------------------------------------------------\n";

?>

Bad output (with "# php <enter> && paste script && ctrl+d):
--------------------------------------------------

      function increment)

       *
       * @access  public
       * @return  int
       */
--------------------------------------------------

Good output:
--------------------------------------------------
/**
       * Increment counter
       *
       * @access  public
       * @return  int
       */
--------------------------------------------------

 [2005-04-22 16:30 UTC] tony2001@php.net
Seems like a compiler problem to me.
That's what I got when running the script via STDIN:

1314            if (fptr->type == ZEND_USER_FUNCTION && fptr->op_array.doc_comment) {
(gdb) p fptr->op_array.doc_comment
$1 = 0x82ce2dc "\n      function increment"

If the script is run via `php script.php` fptr->op_array.doc_comment contains expected value (i.e. the comment itself, without any garbage data).
 [2005-06-07 20:12 UTC] dmitry@php.net
Fixed in CVS HEAD and PHP_5_0.
 
PHP Copyright © 2001-2014 The PHP Group
All rights reserved.
Last updated: Sun Apr 20 03:02:42 2014 UTC