為什么一個類里面只能有一個私有的 我不知道按了什么誰給解釋一下
問題描述
<?php
header('Content-type:text/html;charset=utf-8');
class Staff
{
private $name ;
// public $age ;
//public $salary;
就是這里 不可以 把age 和salary 改成私有的
public function __construct($name,$age,$salary)
{
$this->name = $name;
$this->age = $age;
$this->salary =$salary;
}
public function __get($name)
{
return $this->name;
}
public function __set($name,$value)
{
if($name === 'age')
{
return false;
}
$this->name=$value;
}
}
$obj=new Staff('22',24,500);
//echo $obj->name;
echo $obj->age;
echo '<hr>';
echo $obj->name;
echo '<hr>';
echo $obj->salary;
問題解答
回答1:類里面的私有成員沒有數(shù)量限制
相關(guān)文章:
1. 在mac下出現(xiàn)了兩個docker環(huán)境2. css3 - css怎么實現(xiàn)圖片環(huán)繞的效果3. android - 用textview顯示html時如何寫imagegetter獲取網(wǎng)絡圖片4. javascript - 原生canvas中如何獲取到觸摸事件的canvas內(nèi)坐標?5. css - 定位為absolute的父元素中的子元素 如何設置在父元素的下面?6. JavaScript事件7. javascript - jquery hide()方法無效8. 網(wǎng)頁爬蟲 - 用Python3的requests庫模擬登陸B(tài)ilibili總是提示驗證碼錯誤怎么辦?9. 注冊賬戶文字不能左右分離10. html - vue項目中用到了elementUI問題
