Reputation: 911
as follow:
<?php
/*
* @I'm data
*/
function demo() {}
how to get "I'm data"? thx
Upvotes: 0
Views: 125
Reputation: 31
If your code is inside a class, the correct way is to use reflection:
http://www.php.net/manual/en/reflectionclass.getdoccomment.php
Upvotes: 1
Reputation: 62874
There's no obvious way to do it -- your script is blissfully unaware of its own comments.
However, you could probably hack it by having your script read itself as data, and then parse out whatever you're looking for:
<?php
$my_own_source = file_get_contents(__FILE__);
//some code to pull out exactly what you want here.
Upvotes: 0
Reputation: 61557
Well, if you are accessing it via the demo()
function...
// @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];
}
Upvotes: 2