加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

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

发布时间:2020-12-13 13:14:39 所属栏目: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. Additiona
反思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 ]
  }
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读