• Welcome to Journal web site.

我是 PHP 程序员

- 开发无止境 -

Next
Prev

PHP获取对象中 protected 类型的数据_OHHINK博客

Data: 2016-01-23 20:27:02Form: JournalClick: 8

PHP获取对象中 protected 类型的数据
(8条消息) PHP获取对象中 protected 类型的数据_OHHINK博客-CSDN博客

PHP获取对象中 protected 类型的数据
一般不那么使用,但是真到要用的时候,方法如下

对象如下
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"
    }
  }
}

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68

转化为数据

$data = (array)$object
  • 1

获取数据(重点在这里)

$data["\0*\0accessToken"]->id

 

Name:
<提交>