分享web开发知识

注册/登录|最近发布|今日推荐

主页 IT知识网页技术软件开发前端开发代码编程运营维护技术分享教程案例
当前位置:首页 > IT知识

php (二)

发布时间:2023-09-06 02:21责任编辑:林大明关键词:暂无标签

  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

知识推荐

我的编程学习网——分享web前端后端开发技术知识。 垃圾信息处理邮箱 tousu563@163.com 网站地图
icp备案号 闽ICP备2023006418号-8 不良信息举报平台 互联网安全管理备案 Copyright 2023 www.wodecom.cn All Rights Reserved