如下:
<?php
/*
* @I'm data
*/
function demo() {}
如何获取“我是数据”? THX
答案 0 :(得分:2)
好吧,如果您通过demo()
功能...
// @I'm Data
function demo(){
$script = file(__FILE__);
$comment = $script[__LINE__ - 5]; // 4 lines above, and 1 for arrays
$temp = explode("@", $comment);
return $temp[1];
}
答案 1 :(得分:1)
如果你的代码在一个类中,正确的方法是使用反射:
http://www.php.net/manual/en/reflectionclass.getdoccomment.php
答案 2 :(得分:0)
没有明显的方法可以做到这一点 - 你的剧本幸福地没有意识到自己的评论。
但是,你可以通过让你的脚本将自己读作数据来破解它,然后解析你想要的任何东西:
<?php
$my_own_source = file_get_contents(__FILE__);
//some code to pull out exactly what you want here.