svn: /phpdoc/en/trunk/reference/mongo/mongodb/ execute.xml

From: Date: Tue, 12 Jul 2011 15:25:42 +0000
Subject: svn: /phpdoc/en/trunk/reference/mongo/mongodb/ execute.xml
Groups: php.doc.cvs 
Request: Send a blank email to doc-cvs+get-8465@lists.php.net to get a copy of this message
kristina Tue, 12 Jul 2011 15:25:42 +0000 Revision: http://svn.php.net/viewvc?view=revision&revision=313177 Log: Added explanation of weird mongod js parsing behavior Changed paths: U phpdoc/en/trunk/reference/mongo/mongodb/execute.xml Modified: phpdoc/en/trunk/reference/mongo/mongodb/execute.xml =================================================================== --- phpdoc/en/trunk/reference/mongo/mongodb/execute.xml 2011-07-12 15:15:17 UTC (rev 313176) +++ phpdoc/en/trunk/reference/mongo/mongodb/execute.xml 2011-07-12 15:25:42 UTC (rev 313177) @@ -38,6 +38,56 @@ ]]> </programlisting> </para> + <para> + MongoDB implies a return statement if you have a single statement on a single + line. This can cause some unintuitive behavior. For example, this returns + "foo": + </para> + <programlisting role="php"> +<![CDATA[ +<?php + +$db->execute('"foo";'); + +?> +]]> + </programlisting> + <para> + However, these return &null;: + </para> + <programlisting role="php"> +<![CDATA[ +<?php + +$db->execute('"bar"; "foo";'); // more than one statement + +$db->execute('db.foo.count( +);'); // more than one line + +?> +]]> + </programlisting> + <para> + To avoid surprising behavior, it is best not to depend on MongoDB to decide + what to return, but to explicitly state a return value. In the examples + above, we can change them to: + </para> + <programlisting role="php"> +<![CDATA[ +<?php + +$db->execute('"bar"; return "foo";'); + +$db->execute('return db.foo.count( +);'); + +?> +]]> + </programlisting> + <para> + Now the first statement will return "foo" and the second statement will + return a count of the "foo" collection. + </para> </refsect1> <refsect1 role="parameters">

« previous php.doc.cvs (#8465) next »