Pro PHP- Patterns, Frameworks, Testing and More

(vip2019) #1

(^82) CHAPTER 7 ■ REFLECTION API
If you do not get this output, it is likely that you need to enable the extension in your
php.ini file. To locate the php.ini file, execute the following command:
php -i |grep php.ini
You should get a result similar to this:
Configuration File (php.ini) Path => /etc/php5.1/cli/php.ini
You then need to add the following line to the php.ini file to enable the docblock extension:
extension=docblock.so;
Finally, reexecute the command to check that the docblock tokenizer is installed.
■Note Depending on your server distribution, there may be separate php.ini files for the command line
and web server. Each will need the docblock extension enabled.
Once you have the docblock extension running, you can start parsing docblock comments
using tokenizer-style parsing. However, first you need to actually get the documentation data
to process from the reflection API.


Accessing Doccomment Data.


Listing 7-9 demonstrates how to access doccomment data using reflection.

Listing 7-9. Accessing Doccomments

/**
* This is a doccomment
*
* This doccomment documents the class demo
*/
class demo {}

$reflectionClass = new ReflectionClass('demo');
$docComment = $reflectionClass->getDocComment();

print($docComment);

McArthur_819-9C07.fm Page 82 Friday, February 22, 2008 8:59 AM

Free download pdf