<?php
/**
* Created by PhpStorm.
* User: Administrator
* Date: 2019-12-09
* Time: 0:47
*/
class Ren{
//public private protected static;
var $xm;
var $nl;
var $mz;
public $xb;
private $money;
protected $xa;
function __construct($xm="",$nl="38",$mz="吴",$money="100万"){
$this->xm="wulei";
$this->nl=$nl;
$this->mz=$mz;
$this->money=$money;
}
function sh(){
echo $this->xm."说话,它年龄".$this->nl."名字".$this->mz;
}
function nq(){
echo "拿钱";
}
function xx(){
echo $this->xm;//对象内调用属性使用 $this
$this->sh();//调用sh()方法
}
function sdtx(){
//php面像对象的三大特性(封装,继承,多态)
}
private function za(){
//人做爱,是不可以让别人知道的。私有方法
echo $this->xm."和老婆做爱";
}
public function hqsx(){
//类外获取私有属性的方法
return $this->money;
}
public function hdsx(){
//类外获得私有方法的方法
echo $this->xm."有".$this->money;
}
private function __set($hqmoney,$hqmoneyje){
//通过__set()魔术方法
// if($hqmoney=="100"){
//
// }
echo $this->money;
$this->$hqmoney=$hqmoneyje;
}
function __destruct(){
echo "再见";
}
}
$re=new Ren("李涛","38","sun");
echo $re->xm="wulei";
$re->sh();
$re->xx();//因为echo $re->xm="wulei"; 所以输出结果为 wulei
//$re->za();//不可以调用类中的私有访问和属性
$re->hdsx();
$re->hqsx();
$re->money;
//var_dump($ren);
//object(Ren)[1]
// public 'xm' => null
// public 'nl' => null
// public 'mz' => null
// public 'xb' => null
// private 'money' => null
// protected 'xa' => null