search

Home  >  Q&A  >  body text

The code should be correct, what's going on?

QQ截图20170724161159.jpg22.jpg

比你盖茨比你盖茨2688 days ago1521

reply all(6)I'll reply

  • 天蓬老师

    天蓬老师2017-07-27 08:21:39

    public function __get($name)
    {
        return $this -> $name; //$name是外部传参,属于变量
    }

    Please modify the syntax in your class.

    Also, your syntax for calling attributes of external objects is correct.

    The magic method __get() you defined will only take effect when calling a property that does not exist in the class.


    reply
    2
  • nearest

    nearest2017-07-25 11:39:03

    Add in front:

    private $name = "yourname";


    reply
    0
  • phpcn_u11553

    phpcn_u115532017-07-25 01:22:58

    private $name ='';

    reply
    0
  • mr

    mr2017-07-24 21:27:22

    Must be wrong, you have no definition

    reply
    0
  • Ailon

    Ailon2017-07-24 19:08:51

    There is no $name in your class, how can you use $this->name

    reply
    0
  • 比你盖茨

    If this is the case, then each of the 30 fields must be __get __set 30 times?

    比你盖茨 · 2017-07-25 11:20:04
    Ailon

    You must define $name first like $xm before you can use $this->name; __get and __set only need to be written 30 times. They will be automatically called when you access non-existent or private properties externally.

    Ailon · 2017-07-25 11:31:52
    Ailon

    You must define $name first like $xm before you can use $this->name; __get and __set only need to be written 30 times, and will be automatically called when you access non-existent or private properties externally.

    Ailon · 2017-07-25 11:32:10
  • Pequeño

    Pequeño2017-07-24 17:11:16

        $this->$name 吧

    reply
    0
  • Cancelreply