search

Home  >  Q&A  >  body text

Why can there be only one private in a class? I don’t know what to press. Can anyone explain it?

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

远处一朵花远处一朵花1438 days ago1142

reply all(1)I'll reply

  • 西门大官人

    西门大官人2020-12-18 15:10:37

    There is no limit on the number of private members in a class

    reply
    0
  • Cancelreply