PHP:反思API – 很少添加到PHP中

前端之家收集整理的这篇文章主要介绍了PHP:反思API – 很少添加到PHP中前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
反思API是操作OOP的东西,看起来好像大多数开发人员甚至没有意识到或者从未使用过.

反思API声明:

PHP 5 comes with a complete reflection
API that adds the ability to
reverse-engineer classes,interfaces,
functions,methods and extensions.
Additionally,the reflection API
offers ways to retrieve doc comments
for functions,classes and methods.

题:

为什么它的大多数方法/属性几乎没有文档?您在文档中看到此消息:

This function is currently not
documented; only its argument list is
available.

在哪里找到它的文档?

>它是未来兼容的,换句话说,我可以在我的MVC框架中使用吗?
为什么使用次数较少,有什么问题呢?

反思绝对是留在这里.您可以使用它,但请记住,对于简单的UseCases而言,它被认为是缓慢而过度的.使用 Classes/Objects function package中的一个功能通常是更快的选择.

反思派生的一个UseCase是解析类的DocBlock中的注释.例如,PHPUnit使用注释@test来告诉PHPUnit TestRunner它应该考虑一种方法进行测试. @covers注释将帮助它收集代码覆盖率数据. FLOW3框架利用了Annotations for their AOP framework.

不幸的是,PHP的一些新增功能5.3,还没有记录那么多. Just look at the SPL.同样的事情.这并不意味着你不能使用它. Reflection API非常有表现力,很容易从方法名称中找出.而Google通常会有关于如何使用某些扩展的博文.对于Reflection API,请查看:

> http://www.phpriot.com/articles/reflection-api
> http://mark-story.com/posts/view/using-the-php-reflection-api-for-fun-and-profit
> http://www.tuxradar.com/practicalphp/16/4/0
> http://weierophinney.net/matthew/archives/125-PHP-5s-Reflection-API.html

和SPL

> http://www.phpro.org/tutorials/Introduction-to-SPL.html

我刚才发现的很酷截至5.1.2,您也可以invoke the Reflection API from the command line

$PHP --rf strtotime
Function [ <internal:date> function strtotime ] {

  - Parameters [2] {
    Parameter #0 [ <required> $time ]
    Parameter #1 [ <optional> $now ]
  }
}
原文链接:https://www.f2er.com/php/131288.html

猜你在找的PHP相关文章