thinkphp 钩子(hook)的冷知识

钩子注册

Hook::add('xxx', 'app\common\behavior\Aaa');
$guahaoStatus = Hook::listen('xxx',$sy_id);

预期的返回数据

array(2) {
  [0] => int(-1)
  [1] => string(9) "已取消"
}

实际的返回数据

array(1) {
    array(2) {
      [0] => int(-1)
      [1] => string(9) "已取消"
    }
}

Hook::listen返回的数组,会被包裹一层。

解决方式

$guahaoStatus = Hook::listen('xxx',$sy_id,null,true);