学习php Reflection(二)
(4)映射类(ReflectionClass)
ReflectionClass类允许你反向映射类。
<?
php
interface MySerializable
{
// ...}
class My
Object
{
// ...}
/** A counter class */
class
Counter
extends
MyObject implements MySerializable
{ const
START
=
0
;
private
static
$c
=
Counter
::
START
;
/**Invoke counter
* @access public
* @return int */
public
function
count
() { return
self
::
$c
++; }
}
// Create an instance of the ReflectionClass class
$class
= new
ReflectionClass
(
'Counter'
);
// Print out basic information
printf
(
"===> The %s%s%s %s '%s' [extends %s]\n"
.
" declared in %s\n"
.
" lines %d to %d\n"
.
" having the modifiers %d [%s]\n"
,
$class
->
isInternal
() ?
'internal'
:
'user-defined'
,
$class
->
isAbstract
() ?
' abstract'
:
''
,
$class
->
isFinal
() ?
' final'
:
''
,
$class
->
isInterface
() ?
'interface'
:
'
相关文档:
<?php
//声明数组变量
$arr = array('张三','李四','王五','李明');
//foreach循环遍历数组
foreach($arr as $key => $value){
//注意“$value”后必须要一个空格,否则输出的结果不正确
echo "值$value 的下标为$key<br/ ......
<?php
//获得系统时间函数(注意参数中大写Y代表完整年份,小写y代表年份简写)
$sum = date("Y-m-d");
$sum1 = date("y-m-d");
echo "$sum<br/>";
echo "$sum1<br/>";
//md5加密函数
$pass = md5("张三");
......
编码是个很基础的问题,也是大家很容易忽略的问题,写代码之前多多考虑,以后会少很多麻烦。
PHP发展了不少,现在pear用起来很方便,其中就有相关的class来读取Excel文件里面的内容,如果不想使用pear的话,可以考虑使用excel_class.php,google一下,可以找到这个class的source code下载,也能找到基本的example c ......
<?
class upload{
private $name; //$_FILES['file'][name]
private $type; //$_FILES['file'][type]
privat ......
看yii框架源码的时候,发现了
ReflectionClass这个方法,才发现原来是php5的新东西,于是稍微研究了下。php的反射api一共有:
class
Reflection
{ }
interface Reflector
{ }
class
ReflectionException
extends
Exception
{ }
class
Re ......