保存对象时不允许'零长度键'出现致命错误。
是否存在__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->保存(对象(地址))#1 {main}抛出第105行的/var/www/html/index.php
答案 0 :(得分:10)
嗯,您如何期待mongo阅读您的私有类变量。