method_exists判断方法是否存在

<?php

class F{
public function __construct(){
if(method_exists($this, 'son_fun1')){
echo 'son_fun1存在';
}else{
echo 'son_fun1不存在';
}
if(method_exists($this,'son_fun2')){
echo 'son_fun2存在';
}else{
echo 'son_fun2不存在';
}
}
}
class S extends F{
public function son_fun1(){
}
}
$a = new S();

call_user_func 动态传入函数方法名

<?php
error_reporting(E_ALL);
function increment(&$var)
{
$var++;
} $a = 0;
call_user_func('increment', $a);
echo $a."\n"; // You can use this instead
call_user_func_array('increment', array(&$a));//要被传入回调函数的数组得是索引数组。
echo $a."\n";

 register_shutdown_function当PHP脚本发生致命错误时调用的方法

<?php

    //禁止错误输出
error_reporting(0);
//设置错误处理器
set_error_handler('errorHandler');
register_shutdown_function('fatalErrorHandler');
class Test{
public function index(){
//这里发生一个警告错误,出发errorHandler
echo $undefinedVarible;
}
}
function errorHandler($errno,$errstr,$errfile,$errline){
$arr = array(
'['.date('Y-m-d h-i-s').']',
'http://www.baidu.com',
'|',
$errstr,
$errfile,
'line:'.$errline,
);
//写入错误日志
//格式 : 时间 uri | 错误消息 文件位置 第几行
error_log(implode(' ',$arr)."\r\n",3,'./test.txt','extra');
echo implode(' ',$arr)."\r\n";
} //捕获fatalError
function fatalErrorHandler(){
$e = error_get_last();
switch($e['type']){
case E_ERROR:
case E_PARSE:
case E_CORE_ERROR:
case E_COMPILE_ERROR:
case E_USER_ERROR:
errorHandler($e['type'],$e['message'],$e['file'],$e['line']);
break;
}
}
$test = new Test();
////这里发生一个警告错误,被errorHandler 捕获
$test->index();
//发生致命错误,脚本停止运行触发 fatalErrorHandler
$test = new Tesdt();
$test->index();

  trigger_error() 函数创建用户级别的错误消息。

<?php
if ($usernum>10) {
trigger_error("Number cannot be larger than 10");//Notice: Number cannot be larger than 10 in C:\webfolder\test.php on line 6
} ?>

  __set __get __call __callstatic __isset __unset 几个魔术方法

__set():为私有成员属性设置值的,在对象中设置一个不存在的属性时,会被调用
__get()方法:获取私有成员属性值的,在对象中调用一个不存在的属性时,会被调用
__call():监视一个对象中的其它方法,在对象中调用一个不可访问方法时,会被调用
__callstatic():监视一个对象中的其它静态方法,在对象中调用一个不可访问静态方法时,会被调用
__isset() :当 用isset() 判断对象不可见的属性时(protected/private/不存在的属性)
会引发 __isset()来执行
__unset():当 用unset 销毁对象的不可见属性时, 会引发 __unset();

  

最新文章

  1. 在Eclipse for mac中配置tomcat,使web项目自动部署到tomcat
  2. enmo_day_07
  3. 20145305 《Java程序设计》实验一
  4. mac usb转串口 连接树莓PI
  5. sharepoint 备份和还原site脚本
  6. Conversion to Dalvik format failed with error 1
  7. CentOS, Fedora, or Red Hat一行命令安装apache + mysql + php 及各种依赖库
  8. MySQL数据库主从分离的配置方法
  9. 安装windows 10到固态硬盘实践记录
  10. Zookeeper 3.5启动时 8080端口被占用
  11. linux生成SSH key
  12. 事务 TRANSACTION
  13. SpringBoot整合Quartz定时任务 的简单实例
  14. 【Win7 x64】+【annaconda3】+ 【python3.5.2】+【tensorflow-gpu】 [最终配置 gtx 940mx + Cuda8.0+cudnn v5.1 + tensorflow-gpu1.0.0 ]
  15. block本质探寻四之copy
  16. bzoj1413 [ZJOI2009]取石子游戏
  17. JDBC数据库编程:PreparedStatement接口
  18. Linux centos 6.5 搭建 svn服务器
  19. 2、大O表示法
  20. setTimeOut传参数

热门文章

  1. CAD图与互联网地图网页端相互叠加显示技术分析和实现
  2. 陈胡:Apache SeaTunnel实现 非CDC数据抽取实践
  3. linux篇-linux面试题汇总
  4. 好客租房2-React概述
  5. 好客租房7-React脚手架的使用
  6. python之模块(os、sys、json、subprocess)
  7. Druid数据库连接池使用体验
  8. Kubernetes client-go 源码分析 - ListWatcher
  9. MySQL锁(乐观锁、悲观锁、多粒度锁)
  10. WindowsServer评估版转为正式版并激活