TypechoJoeTheme

至尊技术网

统计
登录
用户名
密码
/
注册
用户名
邮箱
搜索到 221 篇与 的结果
2020-12-30

PHP面向对象的自动加载

PHP面向对象的自动加载
实例化某个类时,如MySQL类,需要先require('mysql.php' );如果类比较多,目录也比较多,require文件时,将会变得麻烦我们需要一个自动化的解决方法--自动加载用法:声明一个函数,并注册为"自动加载函数"当系统发现某个类不存在时,会调用此函数,我们可以在函数中加载需要的类文件<?php function myLoad($class){ require $class . '.php'; } //把myLoad注册成自动加载函数 spl_autoload_register('myLoad'); new mysql();//查看效果
2020年12月30日
1,104 阅读
0 评论
2020-12-30

PHP面向对象中的魔术方法

PHP面向对象中的魔术方法
魔术方法:某种场景下,能够自动调用的方法如: __construct、 __destruct、__set、 __get、 __isset、__unset、__call__construct(): 构造方法,new 实例时,自动调用__destruct(): 析构方法,对象销毁时自动调用__get(属性名): 当读取对象的一个不可见属性时,自动调用,并返回值不可见: 未定义或无权访问时__set(属性名,属性值): 当对一个不可见的属性赋值时,自动调用__isset(属性名): 当用isset,或empty判断一个不可见属性时,自动调用__unset(属性名): 当unset一个不可见属性时,自动调用<?php class Human{ //构造方法,new 实例时,自动调用 public function __construct(){ echo '构造方法'; } //析构方法,对象销毁时自动调用 public function __destruct(){ echo '析构方法'; } ...
2020年12月30日
958 阅读
0 评论
2020-12-29

PHP面向对象中的$this、self、parent

PHP面向对象中的$this、self、parent
<?php // $this 本对象 // self 本类 // parent 父类 class Single { public $rand; public static $ob; //final 方法不能被子类重写,实现单例模式 final protected function __construct() { $this->rand = mt_rand(1000, 9999); } public static function getins() { if (self::$ob == null) { self::$ob = new self(); } return self::$ob; } } var_dump(Single::getins()); class Par { public function __construct() { echo mt_rand(10000, ...
2020年12月29日
906 阅读
0 评论
2020-12-28

PHP中面向对象3种权限详解

PHP中面向对象3种权限详解
public(公有)protected(受保护)private(私有)外部YNN子类中YYN本类中YYY<?php class Human { public $money = '3000'; protected $car = 'BMW'; private $gf = 'mv'; public function par() { echo $this->money; echo $this->car; echo $this->gf; } } class Stu extends Human { public function sub() { echo $this->money; echo $this->car; echo $this->gf; } } $stu = new Stu; $stu->par(); $stu->sub(); //gf没有被继承 echo $s...
2020年12月28日
896 阅读
0 评论
2020-12-15

PHP批量清空删除文件夹、文件

PHP批量清空删除文件夹、文件
<?php //访问链接如http://localhost/qlhc.php?q=123456 if (!isset($_GET['q']) && $_GET['q'] != '123456') { header("location: //$_SERVER[HTTP_HOST]"); exit(); } // 清文件缓存 $dirs = array( realpath(dirname(__DIR__) . '/cache/index/') ); // 清理缓存 foreach ($dirs as $dir) { doRmdir($dir); echo $dir . " 清理成功!"; } /** * 清空/删除 文件夹 * @param string $dirname 文件夹路径 * @param bool $self 是否删除当前文件夹 * @return bool */ function doRmdir($dirname, $self = true) { ...
2020年12月15日
780 阅读
0 评论
2020-12-15

PHP将动态网页生成HTML纯静态网页

PHP将动态网页生成HTML纯静态网页
<?php start(array( 'index_file' => __DIR__ . '/2.php', //你首页的文件名 'cache_file' => __DIR__ . '/cache/index/', //要缓存的路径 'cache_index_file' => 'index.html', //要缓存的文件名 'expire_seconds' => 43200, //过期的秒数(60秒=1分钟) )); function start($config) { $remain_seconds = $file_timestamp = 0; if (hasCached($config, $remain_seconds, $file_timestamp)) { $html = ''; $html .= file_get_contents($config['cache_file'] . $config['cache_index_file']); die($...
2020年12月15日
818 阅读
0 评论

人生倒计时

今日已经过去小时
这周已经过去
本月已经过去
今年已经过去个月

最新回复

  1. 强强强
    2025-04-07
  2. jesse
    2025-01-16
  3. sowxkkxwwk
    2024-11-20
  4. zpzscldkea
    2024-11-20
  5. bruvoaaiju
    2024-11-14

标签云