<?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();

最新文章

  1. PHP之封装一些常用的工具类函数
  2. Linux配置notes
  3. 为Mac Terminal设置代理
  4. PHP 短连接生成
  5. SQLServer 维护脚本分享(07)IO
  6. wordpress the_date 方法 偶尔为空的问题
  7. 166. Fraction to Recurring Decimal -- 将除法的商表示成字符串(循环节用括号表示)
  8. 在线体验K2 BPM微信审批
  9. 关于Json处理的两个实例
  10. 合并果子 (codevs 1063) 题解
  11. How to do Mathematics
  12. Weex 标签控件
  13. 7、Khala设备资源的申请和释放
  14. Computation expressions and wrapper types
  15. JQuery hover toggle事件使用
  16. 简单来说一下ui-route
  17. vue国际化高逼格多语言
  18. ruby配合gem使用sass
  19. linux之cp和scp的使用
  20. 6 vue-cli mock数据

热门文章

  1. 【概率论】1-1:概率定义(Definition of Probability)
  2. mac brew 使用教程
  3. nginx 配置 nodejs 反向代理
  4. 【分享】《美国数学本科生,研究生基础课程参考书目(个人整理)》[DJVU][VERYCD]
  5. Python3 编程之字符串处理
  6. Flex 布局教程实例
  7. kotlin异常类
  8. Editplus的运行JAVA的配置
  9. Python在for循环中更改list值的方法
  10. 阶段5 3.微服务项目【学成在线】_day04 页面静态化_08-freemarker基础-空值处理