php 可以动态的new一个变量类名
生活随笔
收集整理的這篇文章主要介紹了
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我的名字是:譚斌
總結
以上是生活随笔為你收集整理的php 可以动态的new一个变量类名的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 酪蛋白(说一说酪蛋白的简介)
- 下一篇: 2020诛仙圣诞老人坐标(2019诛仙圣