Reputation: 10210
Getting 'zero-length keys are not allowed' FATAL error while saving object.
Is it due to presence of __construct() ?
I believe PHP object is allowed in save() method.
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
Upvotes: 3
Views: 3598
Reputation: 13133
Umm, how do you expect mongo to read your private class variables.
Upvotes: 10