phpreflectiondocblocks

ReflectionMethod->getDocComment() doesn't seem to work on PHP 5.5


I'm trying to make an interface from reflectionMethods for one of my classes, and I've got a problem where the method getDocComments() fails on my staging environment.

Here is the test code I use :

<?php

class foo
{
    /**
     * Method bar description
     *
     * @param string $param1
     * @param int    $param2
     * @return array
     */
    public static function bar($param1, $param2 = 0)
    {
        return array();
    }
}

$r        = new ReflectionMethod('foo', 'bar');
$docBlock = $r->getDocComment();

echo $docBlock;

On my staging environment, $docBlock is empty (set to false if I var_dump() it). The PHP Version I have on the staging environment is PHP Version 5.5.30-1~dotdeb+7.1. On my local environment, with PHP Version 5.6.27-0+deb8u1, it seems to work.

The issue may be very specific to my environment though, I am not able to reproduce it on any online php tester I found (I tested it with PHPTester and Online PHP Functions who allow to test against several versions of PHP, but none had the precise version I have on my environment.


Solution

  • Ok, it seems Zend OPcache was activated on this environment, with these parameters :

    ; If disabled, all PHPDoc comments are dropped from the code to reduce the
    ; size of the optimized code.
    opcache.save_comments=0
    
    ; If disabled, PHPDoc comments are not loaded from SHM, so "Doc Comments"
    ; may be always stored (save_comments=1), but not loaded by applications
    ; that don't need them anyway.
    ;opcache.load_comments=1
    

    with opcache.save_comments set to 0, all the comments (including docBlocks) are removed, therefore not readable.