Blogger Information
Blog 29
fans 0
comment 0
visits 18383
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
重载get
CC
Original
817 people have browsed it

魔术方法get__

  • 将不符号条件属性过滤掉
    1. <?php
    2. // 重载
    3. class Demo
    4. {
    5. //定义私有 属性
    6. private $techer = "杨";
    7. private $role = "1";
    8. // 属性重载,__get魔术方法,不经过属性直接访问到魔术方法
    9. public function __get($name)
    10. {
    11. if ($this->role === "英雄")
    12. return $this->techer;
    13. else
    14. return "非法访问...";
    15. }
    16. }
    17. $obj = new Demo;
    18. echo $obj->$techer;
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post