繁体   English   中英

"无法访问对象 PHP 的私有属性"

[英]Cannot access private property of an object PHP

我目前正在使用 Ratchet websocket,当我尝试打印连接时,我得到了这个对象,我想获取uri->query<\/code>字段,但是当我尝试这样做时,它给了我一个错误,我无法访问私有财产。

我的代码:

GuzzleHttp\Psr7\Request {#772
  -method: "GET"
  -requestTarget: null
  -uri: GuzzleHttp\Psr7\Uri {#773
    -scheme: "http"
    -userInfo: ""
    -host: "localhost"
    -port: 8090
    -path: "/"
    -query: "id=3"
    -fragment: ""
  }
    "Pragma" => array:1 [
      0 => "no-cache"
    ]
    "Cache-Control" => array:1 [
      0 => "no-cache"
    ]
    "Upgrade" => array:1 [
      0 => "websocket"
    ]
    "Origin" => array:1 [
      0 => "http://127.0.0.1:8000"
    ]
    "Sec-WebSocket-Version" => array:1 [
      0 => "13"
    ]
    "User-Agent" => array:1 [
      0 => "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.100 Safari/537.36"
    ]
    "Accept-Encoding" => array:1 [
      0 => "gzip, deflate, br"
    ]
    "Accept-Language" => array:1 [
      0 => "ru-RU,ru;q=0.9,en-US;q=0.8,en;q=0.7,hy;q=0.6"
    ]
    "Sec-WebSocket-Key" => array:1 [
      0 => "apMgrSRt1GBHX5Nhj19gHQ=="
    ]
    "Sec-WebSocket-Extensions" => array:1 [
      0 => "permessage-deflate; client_max_window_bits"
    ]
  ]
  -protocol: "1.1"
  -stream: null
}

该变量是私有的,因此您无法从类外部访问它。 (阅读变量范围

但在您的情况下,您使用的是 Guzzle HTTP 请求对象,正如文档所说:

public getQuery ( mixed $asString = false )

Get the collection of key value pairs that will be used as the query string in the request

所以你可以使用 getQuery 从对象中获取查询。

您可以通过以下方式访问:

$conn->httpRequest->getUri()->getQuery();

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM