保存对象时出现“不允许使用零长度键”的致命错误。
是因为存在 __construct() 吗?
我相信在 save() 方法中允许使用 PHP 对象。
class Address{
private $name;
private $company;
private $zip;
public function __construct($name,$company,$zip){
$this->name = $name;
$this->company = $company;
$this->zip = $zip;
}
}
$newAddress = new Address("james","google",678);
print_r($newAddress);
// Address Object ( [name:Address:private] => james [company:Address:private] =>
// google [zip:Address:private] => 678 )
$addresses->save($newAddress);
致命错误:未捕获的异常 'MongoException' 带有消息“不允许使用零长度键,您是否使用带有双引号的 $?” 在 /var/www/html/index.php:105 堆栈跟踪:#0 /var/www/html/index.php(105): MongoCollection->save(Object(Address)) #1 {main} 抛出 /第 105 行的 var/www/html/index.php