Blogger Information
Blog 4
fans 0
comment 1
visits 4260
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
入门面向对象,第一个实例!
CHEN
Original
548 people have browsed it

实例

<?php
//定义一个Car类并实例化一个对象
class Car{
    //定义属性
    public $name='孙悟空';

    public $ename='齐天大圣';
   //定义方法
    public function getName(){

        return $this->name ."就是" .$this->ename;        
        //方法内部可以使用$this伪变量调用对象的属性或者方法

    }
}

$car=new Car();
//new一个实例化Car对象
$car->getName();

运行实例 »

点击 "运行实例" 按钮查看在线实例


Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
1 comments
CHEN 2021-04-07 19:22:20
return $this->name ."就是" .$this->ename; 修改为:echo $this->name ."就是" .$this->ename;
1 floor
Author's latest blog post