php protected 类型如何获取

感谢

https://blog.csdn.net/m0_38092942/article/details/81354184

比如对象如下

object(App\User)#265 (28) {
  ["attributes":protected]=>
  array(47) {
    ["d"]=>
    int(0)
    ["t"]=>
    int(0)
    ["enable"]=>
    int(1)
  }
  ["original":protected]=>
  array(47) {
    ["d"]=>
    int(0)
    ["t"]=>
    int(0)
    ["enable"]=>
    int(1)
  }
  ["rememberTokenName":protected]=>
  string(14) "remember_token"
  ["accessToken":protected]=>     //此为要获取的数据
  object(Laravel\Passport\Token)#267 (26) {
    ["attributes":protected]=>
    array(9) {
      ["id"]=>
      string(80) "b79367e0ae9e601714cea9c4dbe387a48f82e4b6a01ac53c71ed4c39a86db5991e30bab49b9c29cd"
      ["user_id"]=>
      int(146)
      ["client_id"]=>
      int(4)
      ["name"]=>
      NULL
      ["scopes"]=>
      string(2) "[]"
      ["revoked"]=>
      int(0)
      ["created_at"]=>
      string(19) "2018-08-02 10:01:19"
      ["updated_at"]=>
      string(19) "2018-08-02 10:01:19"
      ["expires_at"]=>
      string(19) "2018-08-17 10:01:19"
    }
    ["original":protected]=>
    array(9) {
      ["id"]=>
      string(80) "b79367e0ae9e601714cea9c4dbe387a48f82e4b6a01ac53c71ed4c39a86db5991e30bab49b9c29cd"
      ["user_id"]=>
      int(146)
      ["client_id"]=>
      int(4)
      ["name"]=>
      NULL
      ["scopes"]=>
      string(2) "[]"
      ["revoked"]=>
      int(0)
      ["created_at"]=>
      string(19) "2018-08-02 10:01:19"
      ["updated_at"]=>
      string(19) "2018-08-02 10:01:19"
      ["expires_at"]=>
      string(19) "2018-08-17 10:01:19"
    }
  }
}

转化为数据

$data = (array)$object

获取数据(重点在这里)

$data["\0*\0accessToken"]->id
posted @ 2018-12-13 15:20  西瓜霜  阅读(2894)  评论(0编辑  收藏  举报