Blogger Information
Blog 19
fans 1
comment 0
visits 12235
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
0506作业
▽空城旧梦
Original
796 people have browsed it

类的自动加载

  1. <?php
  2. spl_autoload_register(function($class){
  3. require $class.'.php';
  4. });

类的基本形式

  1. class Player{
  2. public $name = 'Jordan';
  3. public $height;
  4. public $team;
  5. protected $playerNum;
  6. public function __construct($name,$height,$team,$weight){
  7. $this->name = $name;
  8. $this->height = $height;
  9. $this->team = $team;
  10. $this->weight = $weight;
  11. }
  12. public function jog(){
  13. return "$this->name is jogging, weighing $this->weight<br>";
  14. }
  15. public function shoot(){
  16. return "$this->name is shooting, his height is $this->height<br>";
  17. }
  18. }

类的调用

  1. $np2 = new Player('kobe','206cm','Laker',"85kg");
  2. echo $np2->name;
  3. echo $np2->shoot();

类的静态成员

  1. class User
  2. {
  3. public static $name = '胡歌';
  4. protected $_config = [
  5. 'auth_on'=>'true',
  6. 'auth_type'=>1,
  7. ];
  8. public static $nation = "China";
  9. private static $salary ;
  10. static $count = 0;
  11. public function __construct($name,$salary){
  12. self::$name = $name;
  13. self::$salary = $salary;
  14. self::$count++;
  15. }
  16. public function getConfig(){
  17. return sprintf('认证开关:%s<br>,认证类型:%d',$this->_config['auth_on'],$this->_config['auth_type']);
  18. }
  19. public static function getCount()
  20. {
  21. return sprintf('User类被实例化了%d次<br>',self::$count);
  22. }

类的静态成员调用

  1. ECHO $user2->getCount();
  2. echo User::getCount();
  3. echo User::$name;
  4. echo $user2->getConfig();
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
Author's latest blog post