Thursday, August 27, 2009

Doc Comment could be a source of data!!!

While discussing ways of using PHP as data storage file, we passed over this interesting possibility.

PHP data file: CommentDataClass.php
/**
Doc Comment could be a SOURCE OF DATA
This could be your data in string format!!
*/
class CommentDataClass { }

?>
Retrieving data: Data.php
include_once 'CommentDataClass.php';

// Taking advantage of PHP 5.x Reflection,
// Refer: http://in.php.net/oop5.reflection

$reflectedClass = new ReflectionClass('CommentDataClass');

if(preg_match("/\/\*\*(.*)\*\//s",
$reflectedClass->getDocComment(), $matches)) {
$data = $matches[1];
$data = trim($data);

var_dump(explode("\n", $data));
}
?>
Well, this is just for fun, we don't recommend it for serious use :)

Comments:
Similar topic discussed at: http://googlecode.blogspot.com/2009/09/gmail-for-mobile-html5-series-reducing.html
 
Post a Comment

<< Home

This page is powered by Blogger. Isn't yours?