加载中…
个人资料
  • 博客等级:
  • 博客积分:
  • 博客访问:
  • 关注人气:
  • 获赠金笔:0支
  • 赠出金笔:0支
  • 荣誉徽章:
正文 字体大小:

反射api

(2011-11-06 11:20:36)
标签:

it

分类: php那些事

PHP 5中带有一个完整反射API,增加了逆向工程,接口功能和方法,以及扩展能力此外,反射API还提供了检索功能类和方法文档注释方法

<?php

function counter() 
{
    static 
$c 0;
    return 
$c++;
}

// Create an instance of the ReflectionFunction class
$func = new ReflectionFunction('counter');

// Print out basic information
printf(
    
"===> The %s function '%s'\n".
    
    declared in %s\n".
    
    lines %d to %d\n",
    
$func->isInternal() ? 'internal' 'user-defined',
    
$func->getName(),
    
$func->getFileName(),
    
$func->getStartLine(),
    
$func->getEndline()
);

// Print documentation comment
printf("---> Documentation:\n %s\n"var_export($func->getDocComment(), 1));

// Print static variables if existant
if ($statics $func->getStaticVariables())
{
    
printf("---> Static variables: %s\n"var_export($statics1));
}

// Invoke the function
printf("---> Invokation results in: ");
var_dump($func->invoke());


// you may prefer to use the export() method
echo "\nReflectionFunction::export() results:\n";
echo 
ReflectionFunction::export('counter');
?>

0

阅读 收藏 喜欢 打印举报/Report
  

新浪BLOG意见反馈留言板 欢迎批评指正

新浪简介 | About Sina | 广告服务 | 联系我们 | 招聘信息 | 网站律师 | SINA English | 产品答疑

新浪公司 版权所有