1,stdClass 他是php内置的一个类,提供给我们直接实例化使用。 $obj = new stdClass(); $obj->prop = ‘hello world’; echo $obj->prop; 我们可以看看他的内部结构 Reflection::export(new ReflectionClass(‘stdClass’)); /* 输出结果 Class [ class stdClass ] {
- Constants [0] { }
- Static properties [0] { }
- Static methods [0] { }
- Properties [0] { }
- Methods [0] { } } */ 2,php的exception和error处理 他们各自的发生: exception可以通过php5 的try{}抛出,然后通过catch{}被捕获。 php内置函数执行时发生问题,是通过trigger_error显示error。 使用异常:
// set_error_handler()函数用于让用户自定义错误处理函数 // set_error_handler(error_function, error_type) // error_function 必须, 制定发生错误时运行的函数 // error_type 可选, 规定不同的错误级别提示的不同信息, 默认是"E_ALL" set_error_handler(‘ErrorHandler’);
$foo = 2; if ($foo > 1) { // trigger_error()接收一个错误信息和一个常量作为参数, // 常量为 E_USER_ERROR -> a fatal error // E_USER_WARNING -> a non-fatal error // E_USER_NOTICE -> a report that may not represent an error trigger_error(“A custom error has been trigglered”, E_USER_ERROR); } echo ‘Go on…'; 不同之处,处理异常后,脚本不再执行;但是error有可能会继续执行。 整理一下,可以放到tinymvc里做script plugin。
最后修改于 2010-02-04