0
私はファイルとして、頻繁に変更する必要のある情報を格納するための設定ファイルとしてPHPを使用しています。私のクラスで返されたオブジェクトからnon-objectのプロパティを取得しようとしています
return (object) array(
"host" => array(
"URL" => "https://thomas-smyth.co.uk"
),
"dbconfig" => array(
"DBHost" => "localhost",
"DBPort" => "3306",
"DBUser" => "thomassm_sqlogin",
"DBPassword" => "SQLLoginPassword1234",
"DBName" => "thomassm_CadetPortal"
),
"reCaptcha" => array(
"reCaptchaURL" => "https://www.google.com/recaptcha/api/siteverify",
"reCaptchaSecretKey" => "IWouldNotBeSecretIfIPostedItHere"
)
);
私はこれを呼び出すためのコンストラクタがあります:私はそうのように、オブジェクトとして配列を返す プライベート$の設定を、
function __construct(){
$this->config = require('core.config.php');
}
そして使用はそれが好き:
[18-Apr-2017 21:18:02 UTC] PHP Notice: Trying to get property of non-object in /home/thomassm/public_html/php/lib/CoreFunctions.php on line 21
これはとして返される事を考慮起こっている理由を私は理解していない:
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query(array('secret' => $this->config->reCaptcha->reCaptchaSecretKey, 'response' => $StrToken)));
はしかし、私はエラーを与えています私は別の質問からこの考えを得たので、オブジェクトとそれは他の人のために働くように見えました。助言がありますか?
何ですかstdClassのこと? –
それはオブジェクトです。キャストでオブジェクトを作成したり、クラスを指定していないソースからオブジェクトを作成したりすると、そのオブジェクトは 'stdClass'クラスになります。 – AbraCadaver