Home > php教程 > php手册 > PHP反射类之妙用

PHP反射类之妙用

WBOY
Release: 2016-06-06 19:47:19
Original
906 people have browsed it

//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 ();
?>

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template