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


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM