类
class
new
PHP 命名空间 namespace
构造方法
class Hello{ ???/** ????* Hello constructor. ????* @param $age 年龄/int ????* @param $name 名字/srting ????*/ ???public function __construct($age,$name) // 构造方法 ???{ ???????$this->_age = $age; ???????$this->_name = $name; ???} ???public function getAge(){ ???????return $this->_age; ???} ???public function getName(){ ???????return $this->_name; ???} ???private $_age,$name;}$h = new Hello(10,‘我‘); // 创建实例$h->sayHello();
--------------------------------------------------
成员方法与类方法
static
class Hello{ ???/** ????* Hello constructor. ????* @param $age 年龄/int ????* @param $name 名字/srting ????*/ ???public function __construct($age,$name) // 构造方法 ???{ ???????$this->_age = $age; ???????$this->_name = $name; ???????Hello::$NUM++; ???????if(Hello::$NUM>Hello::MAX_MAN_NUM){ ???????????throw new Exception(‘不能‘); ???????} ???} ???public function getAge(){ ???????return $this->_age; ???} ???public function getName(){ ???????return $this->_name; ???} ???private $_age,$name; ???private static $NUM = 0; // 静态变量 ???const MAX_MAN_NUM = 200; //常量 ???// 都是描述类的 ???public static ?function sayHello(){ ???????echo ‘类‘; ???}}$h = new Hello(10,‘我‘); // 创建实例$h->sayHello();
---------------------------------------------
类的继承
extends
方法重写.可以修改方法内的功能
---------------------------------------------
时间和日期
time()
date_default_timezone_set(‘Asia/Shanghai‘); // 设置时区 不然...echo date(‘Y-m-d H:i:s‘,time());
php (二)
原文地址:https://www.cnblogs.com/mysterious-killer/p/9916392.html