Blogger Information
Blog 19
fans 0
comment 0
visits 13572
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
命名空间、类、类成员、方法及构造方法的使用-第九期(191126作业)
feng
Original
650 people have browsed it

命名空间、类、类成员、方法及构造方法的使用

代码

  1. <?php
  2. namespace namespace_A;
  3. class TEST{
  4. public $num='A';
  5. function __construct()
  6. {
  7. echo '命名空间namespace_A的类TEST的对象创建了.';
  8. }
  9. function getInfo(){
  10. echo '变量$num的值为:'.$this->num;
  11. }
  12. }
  13. namespace namespace_B;
  14. class TEST{
  15. public $num='B';
  16. function __construct()
  17. {
  18. echo '命名空间namespace_B的类TEST的对象创建了.';
  19. }
  20. function getInfo(){
  21. echo '变量$num的值为:'.$this->num;
  22. }
  23. }
  24. $objA=new \namespace_A\TEST();
  25. echo '<br>';
  26. $objA->getInfo();
  27. echo '<br>';
  28. $objB=new TEST();
  29. echo '<br>';
  30. $objB->getInfo();

运行结果

手抄作业

Correcting teacher:查无此人查无此人

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