Home  >  Article  >  Backend Development  >  PHP object-oriented basic concept example tutorial

PHP object-oriented basic concept example tutorial

伊谢尔伦
伊谢尔伦Original
2017-06-30 09:59:48924browse

This article mainly introduces the basic concepts of the PHP introductory tutorialObject-oriented, and briefly analyzes the definition of classes, object creation, and Constructor, member variables, Member method, etc. Friends in need can refer to The examples in this article describe the basic concepts of PHP object-oriented. Share it with everyone for your reference, the details are as follows:

Demo1.php

';
  var_dump($computer1);
?>

Demo2.php

 表示指向
// $computer1 = new Computer();
// echo $computer1 -> _name;
// $computer1 -> _name = 'dell';
// echo $computer1 -> _name;
  class Computer {
    //字段成员的声明格式:修饰符 变量名 [=xxx];
    public $_name; //public 表示共有,类外可以访问
    public $_model;
  }
  //创建一个对象,生产出一台电脑 -> 表示指向
  $computer1 = new Computer();
  //给成员字段赋值
  $computer1 -> _name = '联想';
  //取值
  echo $computer1 -> _name;
?>

Demo3.php

 表示指向
  $computer1 = new Computer();
  $computer1 -> _run();
?>

Demo4.php

 表示指向
// $computer1 = new Computer();
// echo $computer1 -> _name;
// $computer1 -> _name = 'dell';
// echo $computer1 -> _name;
  class Computer {
    //字段成员的声明格式:修饰符 变量名 [=xxx];
    public $_name; //public 表示共有,类外可以访问
    public $_model;
  }
  //创建一个对象,生产出一台电脑 -> 表示指向
  $computer1 = new Computer();
  //给成员字段赋值
  $computer1 -> _name = '联想';
  //取值
  //echo $computer1 -> _name;
  $computer2 = $computer1;
  echo $computer2 -> _name;
?>

Demo5.php

 表示指向
  $computer1 = new Computer();
  $computer1 -> _run('一站式建网站');
?>

Demo6.php

Demo7.php

Demo8.php

 _run();
?>

The above is the detailed content of PHP object-oriented basic concept example tutorial. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn