[英]Error calling a property in a static method
我試圖以靜態方法調用在構造函數中聲明的屬性,但由於沒有結果,我認為我做的方法不正確。 這是我的代碼:
class myClass
{
private static $client;
public function __construct(Client $client)
{
self::$client = $client;
}
public static function getBuses(){
$call = self::$client->get('localhost/api-call');
}
}
這里可能出什么問題了? 我收到此錯誤-在null上調用成員函數get()
這對我有用。 請提供更多代碼以作為Client類使用,或您執行此操作的方式
<?php
class myClass
{
private static $client;
public function __construct(Client $client)
{
self::$client = $client;
}
public static function getBuses(){
$call = self::$client->get('localhost/api-call');
return $call;
}
}
class Client
{
public function get($string)
{
return $string;
}
}
$client = new Client();
$class = new myClass($client);
echo $class::getBuses();
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.