zoukankan      html  css  js  c++  java
  • 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我的名字是:谭斌

  • 相关阅读:
    10.7
    10.5
    周六
    周五
    周四
    周三
    四则运算
    zabbix——yum安装
    Stirling's Formula
    CONTRASTIVE REPRESENTATION DISTILLATION
  • 原文地址:https://www.cnblogs.com/soundcode/p/6903829.html
Copyright © 2011-2022 走看看