<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <title>The MongoDB\BSON\Persistable interface</title> </head> <body><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="class.mongodb-bson-type.html">MongoDB\BSON\Type</a></div> <div class="next" style="text-align: right; float: right;"><a href="class.mongodb-bson-serializable.html">MongoDB\BSON\Serializable</a></div> <div class="up"><a href="book.bson.html">MongoDB\BSON</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div><hr /><div id="class.mongodb-bson-persistable" class="reference"> <h1 class="title">The MongoDB\BSON\Persistable interface</h1> <div class="partintro"><p class="verinfo">(mongodb >=1.0.0)</p> <div class="section" id="mongodb-bson-persistable.intro"> <h2 class="title">Introduction</h2> <p class="para"> Classes may implement this interface to take advantage of automatic ODM (object document mapping) behavior in the driver. During serialization, the driver will inject a <span class="property">__pclass</span> property containing the PHP class name into the data returned by <span class="function"><a href="mongodb-bson-serializable.bsonserialize.html" class="function">MongoDB\BSON\Serializable::bsonSerialize()</a></span>. During unserialization, the same <span class="property">__pclass</span> property will then be used to infer the PHP class (independent of any <a href="mongodb.persistence.deserialization.html#mongodb.persistence.typemaps" class="link">type map</a> configuration) to be constructed before <span class="function"><a href="mongodb-bson-unserializable.bsonunserialize.html" class="function">MongoDB\BSON\Unserializable::bsonUnserialize()</a></span> is invoked. See <a href="mongodb.persistence.html" class="xref">Persisting Data</a> for additional information. </p> <blockquote class="note"><p><strong class="note">Note</strong>: <span class="simpara"> Even if <span class="function"><a href="mongodb-bson-serializable.bsonserialize.html" class="function">MongoDB\BSON\Serializable::bsonSerialize()</a></span> would return a sequential array, injection of the <span class="property">__pclass</span> property will cause the object to be serialized as a BSON document. </span> </p></blockquote> </div> <div class="section" id="mongodb-bson-persistable.synopsis"> <h2 class="title">Interface synopsis</h2> <div class="classsynopsis"> <div class="ooclass"></div> <div class="classsynopsisinfo"> <span class="ooclass"> <strong class="classname">MongoDB\BSON\Persistable</strong> </span> <span class="oointerface">implements <span class="interfacename"><a href="class.mongodb-bson-unserializable.html" class="interfacename">MongoDB\BSON\Unserializable</a></span> </span> <span class="oointerface">, <span class="interfacename"><a href="class.mongodb-bson-serializable.html" class="interfacename">MongoDB\BSON\Serializable</a></span> </span> {</div> <div class="classsynopsisinfo classsynopsisinfo_comment">/* Inherited methods */</div> <div class="methodsynopsis dc-description"> <span class="modifier">abstract</span> <span class="modifier">public</span> <span class="type">array|object</span> <span class="methodname"><a href="mongodb-bson-serializable.bsonserialize.html" class="methodname">MongoDB\BSON\Serializable::bsonSerialize</a></span> ( <span class="methodparam">void</span> )</div> <div class="methodsynopsis dc-description"> <span class="modifier">abstract</span> <span class="modifier">public</span> <span class="type">void</span> <span class="methodname"><a href="mongodb-bson-unserializable.bsonunserialize.html" class="methodname">MongoDB\BSON\Unserializable::bsonUnserialize</a></span> ( <span class="methodparam"><span class="type">array</span> <code class="parameter">$data</code></span> )</div> }</div> </div> </div> </div> <hr /><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="class.mongodb-bson-type.html">MongoDB\BSON\Type</a></div> <div class="next" style="text-align: right; float: right;"><a href="class.mongodb-bson-serializable.html">MongoDB\BSON\Serializable</a></div> <div class="up"><a href="book.bson.html">MongoDB\BSON</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div></body></html>