欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  后端开发

php 类定义和类使用实例

程序员文章站 2022-06-05 20:52:24
...
  1. class emp
  2. {
  3. var $name;
  4. var $address;
  5. var $dept;
  6. function assign_info($n,$a,$d)
  7. {
  8. $this->name=$n;
  9. $this->state=$a;
  10. $this->dept=$d;
  11. }
  12. function display_info()
  13. {
  14. echo("

    Employee Name : $this->name");

  15. echo("

    State : $this->state");

  16. echo("

    Department : $this->dept");

  17. }
  18. }
  19. $empobj = new emp;
  20. $empobj->assign_info("kaka lname","California","Accounts");
  21. echo("

    Displaying Employee Information

    ");
  22. echo("");
  23. $empobj->display_info();
  24. echo("
  25. ");
  26. ?>
复制代码

php