文章详情页
为什么一个类里面只能有一个私有的 我不知道按了什么谁给解释一下
问题描述
<?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:类里面的私有成员没有数量限制
上一条:PHP无法生成首页下一条:老师我的phpstudy页面为啥是这样
相关文章:
1. node.js - 怎么在初始化的时候使得一个子组件不加载?2. 代码如下,java用BigDecimal四舍五入怎么还有问题呀?哪种方式是完全没有问题的?3. angular.js - 请教angularjs里html和js通信的问题4. 求解决方法:Parse error: syntax error, unexpected5. 新人做网站求帮助6. java - mybatis里的REGEXP7. Linux服务器下怎么把phpStudy卸载干净8. 请问连接文件怎么写9. 没太明天这样写的作用10. mysql - thinkphp5 在MAC电脑本地正常,部署LINUX服务器之后,模型不存在
排行榜