这是我的PHP代码
<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
class stripeContact{
public $ID;
public $amount;
public $amount_refunded;
public $currency;
public $profileName;
public $profileID;
public $fingerprint;
public $cardEmail;
public $createDate;
public $description;
public $paymentID;
public $logID;
}
class set{
private $stripeOb;
function __construct($input){
$input = (array) $input;
var_dump($input);
$this->stripeOb = new stripeContact();
$this->stripeOb->ID = $input["id"];
$this->stripeOb->amount = $input["amount"];
$this->stripeOb->amount_refunded = $input["amount_refunded"];
$this->stripeOb->description = $input["description"];
$this->stripeOb->logID = "-999";
}
public function stripe(){
return new log($this);
}
}
class log{
private $dbTableName = "stripeLog";
private $client;
function __construct($client){
$this->$client = $client;
}
public function save(){
// save to sql code
}
}
?>
并且在另一个php类中我正在调用类 set 。
$stripe = new set($onlinePay);
$resStripe = $stripe->stripe()->save();
当我打电话给我这个错误时
Catchable fatal error</b>: Object of class set could not be converted to string in
此行中出现此错误
function __construct($client){
$this->$client = $client;
}
我在做错了什么。我将整个 set 类实例传递给日志类中的构造函数。
答案 0 :(得分:2)
$this->$client = $client;
^
摆脱$
,其他一切都很好。错字导致不必要的转换,从而产生错误。
答案 1 :(得分:0)
您应该更改您的课程命名方式。 set是php中的保留字。
示例:
class setStripe {
}
而不是
class set {
}
希望它有所帮助。