Blogger Information
Blog 65
fans 3
comment 4
visits 67810
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
PHP之面向对象
无耻的鱼
Original
826 people have browsed it

面向对象

其实就是相当于对象就是一个工厂

工厂有工具*属性  有生产车间*方法,等等

面向对象说白了 就是一个分类,分类里有属性()商品,,以及商品怎么用(方法)


下边看看代码,力求用最简单的代码来学习复杂知识.

实例
<?php
/**
 * User: Z先生
 * Date: 2018/5/3
 */

class One{
    private $age = '18岁';
    public $name;

    public function __construct(){
        echo '假装数据库连接成功';
    }


    //访问不存在的或者权限不够的
    public function __get($name)
    {
        if($this->name == 'admin'){
            return $this->age;
        }

    }

    //
    public function __set($name, $value)
    {
        if($this->name == 'admin'){
           return $this->$name = $value;
        }else{
            echo '权限不够';
        }
    }
}

//实例化
$a = new One();
echo '<br>';


$a->name = 'admin';
echo $a->age;


echo '<br>';
$a->age = 26;
echo $a->age;


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


Correction status:Uncorrected

Teacher's comments:
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
2018-05-03 19:53:29
...
1 floor
Author's latest blog post