print_r($str)的结果如下,想调用[dot:protected]里的数据,用$rs[dot:protected]调用不了
AlibabaCloud\Client\Result\Result Object
(
[request:protected] => AlibabaCloud\Client\Request\RpcRequest Object
(
[dateTimeFormat:AlibabaCloud\Client\Request\RpcRequest:private] => Y-m-d\TH:i:s\Z
[method] => GET
[format] => JSON
[scheme:protected] => http
[client] => default
[uri] => GuzzleHttp\Psr7\Uri Object
(
[scheme:GuzzleHttp\Psr7\Uri:private] => http
[userInfo:GuzzleHttp\Psr7\Uri:private] =>
[host:GuzzleHttp\Psr7\Uri:private] => slb.aliyuncs.com
[port:GuzzleHttp\Psr7\Uri:private] =>
[path:GuzzleHttp\Psr7\Uri:private] =>
[query:GuzzleHttp\Psr7\Uri:private] =>
[fragment:GuzzleHttp\Psr7\Uri:private] =>
)
[data] => Array
(
)
[userAgent:AlibabaCloud\Client\Request\Request:private] => Array
(
)
[protocol:GuzzleHttp\Psr7\Response:private] => 1.1
[stream:GuzzleHttp\Psr7\Response:private] => GuzzleHttp\Psr7\Stream Object
(
[stream:GuzzleHttp\Psr7\Stream:private] => Resource id #13
[size:GuzzleHttp\Psr7\Stream:private] =>
[seekable:GuzzleHttp\Psr7\Stream:private] => 1
[readable:GuzzleHttp\Psr7\Stream:private] => 1
[writable:GuzzleHttp\Psr7\Stream:private] => 1
[uri:GuzzleHttp\Psr7\Stream:private] => php://temp
[customMetadata:GuzzleHttp\Psr7\Stream:private] => Array
(
)
)
[dot:protected] => Adbar\Dot Object
(
[items:protected] => Array
(
[CommonName] => pull.gd.cn
[RegionIdAlias] => cn-shenzhen
[ResourceGroupId] => rg-acfm4ihk6fxbm4i
[Fingerprint] => 88:fb:e6:71:06:53:a4:4f:3d:f8:0c:3d:e1:4b:48:22:1f:51:7b:69
[ServerCertificateId] => 1968015864633073_16eb60b02d6_1187216945_251128983
[SubjectAlternativeNames] => Array
(
[SubjectAlternativeName] => Array
(
[0] => pull.gd.cn
)
)
[ExpireTimeStamp] => 1582700337000
[AliCloudCertificateId] =>
[ExpireTime] => 2020-02-26T06:58:57Z
[RegionId] => cn-shenzhen
[RequestId] => 14382365-D482-4B7E-B53C-CA256538CC43
[ServerCertificateName] => Cer-pull.gd.cn
[IsAliCloudCertificate] => 0
[AliCloudCertificateName] =>
)
)
)
1
baiyi 2019-11-29 15:42:03 +08:00
protected
封装了,去找暴露出来的方法吧 |
2
explon 2019-11-29 15:46:33 +08:00
这是对象,不是数组!
|
3
littleylv 2019-11-29 15:47:35 +08:00 4
槽点非常多。楼主我看你一年前就在问 PHP 相关的问题了,也不像是新手啊,但槽点相当多
1、“想调用[dot:protected]里的数据,用$rs[dot:protected]调用不了”,假设真可以调,也不是 $rs[dot:protected] ,而是 $rs->dot 2、dot:protected,实例里是无法访问的,除非类有暴露出来,比如 public function getDot() { return $this->dot; } 那么你可以用 $rs->getDot(); 3、看 SDK 文档比来问快。https://github.com/aliyun/openapi-sdk-php-client/blob/c3ddbd02b3216ff428adeae0b724947cbe66820a/src/Traits/HasDataTrait.php 根据源码,照道理你不应该想要获取 dot,而是里面的数据,用法如下: $rs->get('items'); // 结果是 [items:protected] => Array 总之我很想吐槽你 |
5
tabris17 2019-11-29 15:51:54 +08:00
利用 php 的反射,通过 ReflectionMethod::setAccessible 将属性设置成可访问
|
6
littleylv 2019-11-29 15:53:01 +08:00
@littleylv #3
更正,楼主 17 年 11 月就在做 PHP 了( https://v2ex.com/t/402652 ) 2 年的 PHP 经验问出这样的问题……emmmm 难怪大家都黑 PHP |
7
frozenway OP @littleylv 哈哈,大意了,没去看文档,```->request()->toArray();```用 toArray 方法转一下才行
|
8
wangyzj 2019-11-29 15:58:00 +08:00
面向对象没学好
|
10
netherlanddennis 2019-11-29 17:23:14 +08:00
oop,学习下
|
11
zibber 2019-11-29 19:37:50 +08:00
一般会有->getter() 获取对象的方法
|
12
index90 2019-11-29 19:59:46 +08:00
protected 的,难道不是 extend 一下就可以调了吗?
|
13
NerverLibis 2019-11-29 20:12:56 +08:00 via iPhone
单身狗真惨
|
14
zhuzhibin 2019-11-30 17:08:30 +08:00 via iPhone
233
|