Blogger Information
Blog 20
fans 0
comment 0
visits 8101
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
include和require的区别/实例演示:类与对象关键字 魔术方法
P粉191340380
Original
330 people have browsed it

include和require的区别

  1. // include
  2. // 相对路径
  3. include 'inc/hello.php';
  4. // 绝对路径
  5. include __DIR__ . '/inc/hello.php';
  6. echo $username;
  7. // require
  8. // 当路径不存在,代码出错后直接退出
  9. require __DIR__ . 'inc/hello1.php';
  10. echo $username;

类与对象关键字 魔术方法

  1. class Stu{
  2. public $username;
  3. private $age = 18;
  4. static $tel;
  5. public function __construct($username, $age, $tel)
  6. {
  7. $this ->username = $username;
  8. $this ->age = $age;
  9. $this ->tel = $tel;
  10. }
  11. public function __get($age)
  12. {
  13. if($age === 'age'){
  14. return $this ->$age + 5;
  15. }
  16. }
  17. public function __set($age, $value)
  18. {
  19. if($age === 'age'){
  20. if($value >=18 && $value <=30){
  21. $this ->$age =$value;
  22. } else{
  23. echo '你超龄了';
  24. }
  25. }
  26. }
  27. }
  28. $user = new Stu('小李', 19, 13632801080);
  29. echo $user ->age, '<br>';
  30. $user->age = 48;
Correcting teacher:PHPzPHPz

Correction status:qualified

Teacher's comments:
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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!