3
获取'零长度键不被允许'保存对象时出现致命错误。无法在mongodb中保存PHP对象
是否由于__construct()的存在?
我相信PHP对象在save()方法中是允许的。
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);
Fatal error: Uncaught exception 'MongoException' with message 'zero-length keys are not allowed, did you use $ with double quotes?' in /var/www/html/index.php:105 Stack trace: #0 /var/www/html/index.php(105): MongoCollection->save(Object(Address)) #1 {main} thrown in /var/www/html/index.php on line 105
感谢泰勒公开后,我能够成功保存。 – 2012-03-21 17:00:17