PHP

    /*
    * 类的实现
    */

    //声明一个类
    class Person {
        //私有字段
        private $name;
        private $sex;
        private $age;
        
        //构造函数
        function __construct($name, $sex, $age){
           $this->name = $name;
           $this->sex  = $sex;
           $this->age  = $age;
        }
        
        //显示属性值方法
        public function _show(){
            echo $this->name."&".$this->sex."&".$this->age;
        }
    }

    //实例化一个对象
    $person = new Person('李华', '', '18');

    //调用类中的方法
    $person->_show();
原文地址:https://www.cnblogs.com/KTblog/p/4985575.html