2012-03-21 6 views
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

答えて

10

ウムは、あなたが期待していますどのようにあなたのプライベートクラス変数を読み取ることモンゴ。

+0

タイラーに感謝します。公開した後、私は正常に保存することができます。 –

関連する問題