1. 模型属性不知道哪里修改?
直接覆盖模型的 setAttribute
方法,监测到某一个属性改动的时候,抛一个异常就可以看到堆栈了
1 2 3 4 5 6 7 8 9 10 11 12 13
   | use Illuminate\Database\Eloquent\Model;
  class Person extends Model {     public function setAttribute($key, $value)     {         if ($key == 'xxx') {              throw new \RuntimeException;         }
          return parent::setAttribute($key, $value);     } }
   | 
 
有多个地方修改?抛异常,捕获写 log,然后去 log 里面看。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
   | use Illuminate\Database\Eloquent\Model;
  class Person extends Model {     public function setAttribute($key, $value)     {         if ($key == 'xxx') {              try {                 throw new \RuntimeException;             } catch (\RuntimeException $e) {                 \Log::error($e->getTraceAsString());             }         }
          return parent::setAttribute($key, $value);     } }
   | 
 
2. Try to get property of
non-object ?
1 2 3
   | $a = null;
  var_dump($a->c);
   | 
 
对于这种场景,我们也可以 try catch,然后在异常处理里面 dump
上下文一些关键的变量、对象这些东西。