downloads | documentation | faq | getting help | mailing lists | licenses | wiki | reporting bugs | php.net sites | conferences | my php.net

search for in the

ReflectionClass::getEndLine> <ReflectionClass::getDefaultProperties
[edit] Last updated: Fri, 24 May 2013

view this page in

ReflectionClass::getDocComment

(PHP 5 >= 5.1.0)

ReflectionClass::getDocCommentObtener los comentarios de documentación

Descripción

public string ReflectionClass::getDocComment ( void )

Obtiene los comentarios de documentación de una clase.

Advertencia

Esta función no está documentada actualmente, solamente se encuentra disponible la lista de parámetros.

Parámetros

Esta función no tiene parámetros.

Valores devueltos

Los comentarios de documentación, o FALSE si no existiera.

Ejemplos

Ejemplo #1 Ejemplo de ReflectionClass::getDocComment()

<?php
/** 
* Clase de prueba
*
* @param  foo bar
* @return baz
*/
class ClaseDePrueba { }

$rc = new ReflectionClass('ClaseDePrueba');
var_dump($rc->getDocComment())
?>

El resultado del ejemplo sería:

string(55) "/** 
* Clase de prueba
*
* @param  foo bar
* @return baz
*/"

Ver también



add a note add a note User Contributed Notes ReflectionClass::getDocComment - [3 notes]
up
1
uramihsayibok, gmail, com
2 years ago
According to what I can find in the PHP (5.3.2) source code, getDocComment will return the doc comment as the parser found it.
The doc comment (T_DOC_COMMENT) must begin with a /** - that's two asterisks, not one. The comment continues until the first */. A normal multi-line comment /*...*/ (T_COMMENT) does not count as a doc comment.

The doc comment itself includes those five characters, so <?php substr($doccomment, 3, -2) ?> will get you what's inside. A call to trim() after is recommended.
up
1
joe dot scylla at gmail dot com
3 years ago
If you're using a bytecode cache like eAccelerator this method will return FALSE even if there is a properly formatted Docblock. It looks like the information required by this method gets stripped out by the bytecode cache.
up
-1
leosouza at hotmail dot com
3 years ago
The code getDocComment() is not as effective as it seems, a method with a well-crafted regular expression, can solve some problems that this method does not address, for example: Some comments that begin with "/ *" will not be returned in a file too extensive.

The method below shows how you can use a regular expression to get better results.

This code snippet captures the comments in a file. "Php" and replaces it with an empty string, ie "cut" the comments of a class:

<?php
   
public function getComments() {

       
$expr = "/((?:\/\*(?:[^*]|(?:\*+[^*\/]))*\*+\/)|(?:\/\/.*))/";

       
$filename = $this->fileDir; //file directory
       
$file = fopen($filename, "r");
       
$length = filesize($filename);
       
$comments = fread($file, $length);

       
preg_match_all($expr, $comments, $matchs); //capture the comments

       
foreach($matchs[0] as $id => $variable){
           
$comments = str_replace($variable,'',$comments); // replace the scores of empty
       
}
       
fclose($file);
       
$file = fopen($filename, "w");
       
$file = fwrite($file, $comments);
    }
?>

 
show source | credits | sitemap | contact | advertising | mirror sites