欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  php教程

PHP反射类之妙用

程序员文章站 2022-06-07 18:24:30
...

//PHP Reflection Class is to create a instance of a class which name isspecified ?php class abc { private $p1; private $p2; function __construct($array) { $this-p1 = $array [0]; $this-p2 = $array [1]; } function getP1() { return $this-p1;

//PHP Reflection Class is to create a instance of a class which name is specified

class abc {
private $p1;
private $p2;

function __construct($array) {
$this->p1 = $array [0];
$this->p2 = $array [1];
}

function getP1() {
return $this->p1;
}

function getP2() {
return $this->p2;
}
}

$arr = array (0 => 'p1', 1 => 'p2' );
$class = new ReflectionClass ( 'abc' );
$aObj = $class->newInstance ( $arr );
echo $aObj->getP1 ();
echo $aObj->getP2 ();
?>