发布于 2017-08-10 10:45:43 | 143 次阅读 | 评论: 0 | 来源: 网友投递

这里有新鲜出炉的PHP设计模式,程序狗速度看过来!

PHP开源脚本语言

PHP(外文名: Hypertext Preprocessor,中文名:“超文本预处理器”)是一种通用开源脚本语言。语法吸收了C语言、Java和Perl的特点,入门门槛较低,易于学习,使用广泛,主要适用于Web开发领域。PHP的文件后缀名为php。


这篇文章主要介绍了php面向对象之反射功能与用法,结合实例形式简单分析了php5面向对象反射的概念及具体用法,需要的朋友可以参考下

本文实例讲述了php面向对象之反射功能与用法。分享给大家供大家参考,具体如下:

个人对反射定义的理解:

首先得说说什么叫反射。对于一个新手来说,反射这个概念常常给人一种似懂非懂的 感觉,不知道该如何下手操作。

反射是指:指在PHP运行状态中,扩展分析PHP程序,导出或提取出关于类、方法、属性、参数等的详细信息,同时也包括注释。这种动态获取的信息以及动态调用对象的方法 的功能称为反射API。反射是操纵面向对象范型中元模型的API,其功能十分强大,可帮助我们构建复杂,可扩展的应用。(注意:php中这种反向操作,实在PHP5之后才完全具备

下面在此我用实例进行说明:


class test{
     private   $A;
     public   $B;
     protected  $C;
     public function test(){
       return "this is a test function";
     }
}
//实例化一个反射类ReflectionClass
$obj=new ReflectionClass('test');
echo $obj."<br>";
//实例化test类,并访问其test方法
$obj2=$obj->newInstance();
echo $obj2->test();

个人实例返回结果:


/** * xxx.php * ============================================== * Copy right 2012-2015 * ---------------------------------------------- * This is not a free software, without any authorization is not allowed to use and spread. * ============================================== * @Author:YeXianMing * @Email:LangWaiShiGe@hotmail.com * @Version:zend studio10.6.2 php5.4.38 apache2.2 */ Class [ class test ] { @@ D:\www\MyProjecttest\index5.php 13-21 - Constants [0] { } - Static properties [0] { } - Static methods [0] { } - Properties [3] { Property [ private $A ] Property [ public $B ] Property [ protected $C ] } - Methods [1] { Method [ public method test ] { @@ D:\www\MyProjecttest\index5.php 18 - 20 } } }
this is a test function

希望本文所述对大家PHP程序设计有所帮助。



最新网友评论  共有(0)条评论 发布评论 返回顶部

Copyright © 2007-2017 PHPERZ.COM All Rights Reserved   冀ICP备14009818号  版权声明  广告服务