PHP Doku:: Gets doc comments - reflectionclass.getdoccomment.html

Verlauf / Chronik / History: (1) anzeigen

Sie sind hier:
Doku-StartseitePHP-HandbuchFunktionsreferenzVariablen- und typbezogene ErweiterungenReflectionThe ReflectionClass classReflectionClass::getDocComment

Ein Service von Reinhard Neidl - Webprogrammierung.

The ReflectionClass class

<<ReflectionClass::getDefaultProperties

ReflectionClass::getEndLine>>

ReflectionClass::getDocComment

(PHP 5 >= 5.1.0)

ReflectionClass::getDocCommentGets doc comments

Beschreibung

public string ReflectionClass::getDocComment ( void )

Gets doc comments from a class.

Warnung

Diese Funktion ist bis jetzt nicht dokumentiert. Es steht nur die Liste der Argumente zur Verfügung.

Parameter-Liste

Diese Funktion hat keine Parameter.

Rückgabewerte

The doc comment if it exists, otherwise FALSE

Beispiele

Beispiel #1 ReflectionClass::getDocComment() example

<?php
/** 
* A test class
*
* @param  foo bar
* @return baz
*/
class TestClass { }

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

Das oben gezeigte Beispiel erzeugt folgende Ausgabe:

string(55) "/** 
* A test class
*
* @param  foo bar
* @return baz
*/"

Siehe auch


3 BenutzerBeiträge:
- Beiträge aktualisieren...
uramihsayibok, gmail, com
16.09.2010 6:50
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.
leosouza at hotmail dot com
26.02.2010 19:10
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);
    }
?>
joe dot scylla at gmail dot com
14.10.2009 17:23
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.



PHP Powered Diese Seite bei php.net
The PHP manual text and comments are covered by the Creative Commons Attribution 3.0 License © the PHP Documentation Group - Impressum - mail("TO:Reinhard Neidl",...)