php 可以动态的new一个变量类名


<?PHP
header("content-type:text/html; charset=utf-8");
//echo ucfirst('a b');

class Student{
 private $xh;
 private $name;
 
 function __construct($id,$name){
  $this->id = $id;
  $this->name = $name;
 }
 
 function hello(){
  echo '我的学号是:'.$this->id.'我的名字是:'.$this->name;
 }
}

$className = 'Student';
$stu = new $className('123456','谭斌');
$stu->hello();
?>

 

页面打印结果如下:

我的学号是:123456我的名字是:谭斌


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM