0506作业
16lz
2021-05-18
类的自动加载
<?php
spl_autoload_register(function($class){
require $class.'.php';
});
类的基本形式
class Player{
public $name = 'Jordan';
public $height;
public $team;
protected $playerNum;
public function __construct($name,$height,$team,$weight){
$this->name = $name;
$this->height = $height;
$this->team = $team;
$this->weight = $weight;
}
public function jog(){
return "$this->name is jogging, weighing $this->weight<br>";
}
public function shoot(){
return "$this->name is shooting, his height is $this->height<br>";
}
}
类的调用
$np2 = new Player('kobe','206cm','Laker',"85kg");
echo $np2->name;
echo $np2->shoot();
类的静态成员
class User
{
public static $name = '胡歌';
protected $_config = [
'auth_on'=>'true',
'auth_type'=>1,
];
public static $nation = "China";
private static $salary ;
static $count = 0;
public function __construct($name,$salary){
self::$name = $name;
self::$salary = $salary;
self::$count++;
}
public function getConfig(){
return sprintf('认证开关:%s<br>,认证类型:%d',$this->_config['auth_on'],$this->_config['auth_type']);
}
public static function getCount()
{
return sprintf('User类被实例化了%d次<br>',self::$count);
}
类的静态成员调用
ECHO $user2->getCount();
echo User::getCount();
echo User::$name;
echo $user2->getConfig();
更多相关文章
- 熔断原理与实现Golang版
- 百度静态网站全站搜索功能
- 【PHP 面向对象】面向对象(OOP)编程之魔术方法实现重载知识点归
- 打造立体化监控体系与APM最佳实践系列 --Zipkin部署与使用
- PHP:oop->抽象类/接口/后期静态绑定/单例模式连接数据库 Db类中
- Django 静态文件模板路径配置
- PHP:OOP基础/类(对象抽象化的结果)与对象 (类实例化结果)/构造方
- 【大家的项目】Rust Base62 库学习和分析
- php之类与继承