您的位置:首頁技術文章
文章詳情頁

為什么一個類里面只能有一個私有的 我不知道按了什么誰給解釋一下

瀏覽:140日期:2022-06-03 17:28:45

問題描述

<?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:

類里面的私有成員沒有數量限制

相關文章:
国产综合久久一区二区三区