- 类成员属性和方法的访问必须通过对象才能访问,类外部可以通过实例化得到类对象从而实现成员访问,但是类内部不能访问类外部的对象,此时类的内部就内置了一个对象$this代表来访问对象
<?php
class Saler{
public $count = 100;
protected $discount = 0.8;
private $money = 100;
public function getAll(){
echo $count,$discount,$money;
}
}
$temp = new Saler();
$temp->getAll();
<?php
class Saler{
public $count = 100;
protected $discount - 0.8;
private $money = 100;
public function getAll(){
global $s;
echo $s->count,$s->discount,$s->money;
}
}
$temp = new Saler();
$s->getAll();
$temp1 = new Saler();
$temp1->count = 888;
$temp1->getAll();
<?php
class Saler{
public $count = 33;
protected $diccount = 927;
private $money = 888;
public function getAll(){
var_dump($this);
echo $this->count,$this->discount,$this->money;
}
}
$temp = new Saler();
$temp->getAll();
$temp1 = new Saler();
$temp1->count = 88888;
$temp1->getAll();