php静态调用非静态方法
2024-10-19 07:40:30
<?php
/**
* php静态调用非静态方法
* author: 百里
* Date: 2019/7/18
* Time: 17:28
*/
function dump(...$var) {
foreach ($var as $v) {
var_dump($v);
}
}
class Model
{
private $where = [];
private $update = [];
private static $self = null;
/**
* @return null|Projects
*/
private static function getInstance() {
return new self();
}
public function where($field, $value) {
$obj = self::getInstance();
$obj->where[$field] = $value;
return $obj;
}
public function update(array $params) {
$obj = self::getInstance();
$obj->update = $params;
}
public function get() {
dump(self::getInstance()->where);
}
/**
* 实现静态调用非静态方法
* @param $method
* @param $arguments
* @return mixed
* @throws Exception
*/
public static function __callStatic($method, $arguments)
{
$obj = self::getInstance();
if (method_exists($obj, $method)) {
return call_user_func_array([$obj, $method], $arguments);
}
throw new Exception('static is call failed');
}
}
Model::where('ab', 100)->update([100]);
Model::where('ab', 200)->update([200]);
Model::get();
Model::get();
Model::get();
最新文章
- PHP之封装一些常用的工具类函数
- Linux配置notes
- 为Mac Terminal设置代理
- PHP 短连接生成
- SQLServer 维护脚本分享(07)IO
- wordpress the_date 方法 偶尔为空的问题
- 166. Fraction to Recurring Decimal -- 将除法的商表示成字符串(循环节用括号表示)
- 在线体验K2 BPM微信审批
- 关于Json处理的两个实例
- 合并果子 (codevs 1063) 题解
- How to do Mathematics
- Weex 标签控件
- 7、Khala设备资源的申请和释放
- Computation expressions and wrapper types
- JQuery hover toggle事件使用
- 简单来说一下ui-route
- vue国际化高逼格多语言
- ruby配合gem使用sass
- linux之cp和scp的使用
- 6 vue-cli mock数据
热门文章
- 【概率论】1-1:概率定义(Definition of Probability)
- mac brew 使用教程
- nginx 配置 nodejs 反向代理
- 【分享】《美国数学本科生,研究生基础课程参考书目(个人整理)》[DJVU][VERYCD]
- Python3 编程之字符串处理
- Flex 布局教程实例
- kotlin异常类
- Editplus的运行JAVA的配置
- Python在for循环中更改list值的方法
- 阶段5 3.微服务项目【学成在线】_day04 页面静态化_08-freemarker基础-空值处理