diff --git a/docs/en/cookbook/implementing-wakeup-or-clone.rst b/docs/en/cookbook/implementing-wakeup-or-clone.rst deleted file mode 100644 index 0908dd09c..000000000 --- a/docs/en/cookbook/implementing-wakeup-or-clone.rst +++ /dev/null @@ -1,77 +0,0 @@ -Implementing Wakeup or Clone -============================ - -.. sectionauthor:: Roman Borschel - -As explained in the -:doc:`restrictions for document classes in the manual <../reference/architecture>`. -it is usually not allowed for a document to implement ``__wakeup`` -or ``__clone``, because Doctrine makes special use of them. -However, it is quite easy to make use of these methods in a safe -way by guarding the custom wakeup or clone code with a document -identity check, as demonstrated in the following sections. - -Safely implementing \_\_wakeup ------------------------------- - -To safely implement ``__wakeup``, simply enclose your -implementation code in an identity check as follows: - -.. code-block:: php - - id !== null) { - // ... Your code here as normal ... - } - // otherwise do nothing, do NOT throw an exception! - } - - //... - } - -Safely implementing \_\_clone ------------------------------ - -Safely implementing ``__clone`` is pretty much the same: - -.. code-block:: php - - id !== null) { - // ... Your code here as normal ... - } - // otherwise do nothing, do NOT throw an exception! - } - - //... - } - -Summary -------- - -As you have seen, it is quite easy to safely make use of -``__wakeup`` and ``__clone`` in your documents without adding any -really Doctrine-specific or Doctrine-dependant code. - -These implementations are possible and safe because when Doctrine -invokes these methods, the documents never have an identity (yet). -Furthermore, it is possibly a good idea to check for the identity -in your code anyway, since it's rarely the case that you want to -unserialize or clone a document with no identity. \ No newline at end of file diff --git a/docs/en/reference/architecture.rst b/docs/en/reference/architecture.rst index 9ff13338c..aff153331 100644 --- a/docs/en/reference/architecture.rst +++ b/docs/en/reference/architecture.rst @@ -15,13 +15,6 @@ be any regular PHP class observing the following restrictions: - All persistent properties/field of any document class should always be private or protected, otherwise lazy-loading might not work as expected. -- A document class must not implement ``__clone`` or - :doc:`do so safely <../cookbook/implementing-wakeup-or-clone>`. -- A document class must not implement ``__wakeup`` or - :doc:`do so safely <../cookbook/implementing-wakeup-or-clone>`. - Also consider implementing - `Serializable `_ - instead. - Any two document classes in a class hierarchy that inherit directly or indirectly from one another must not have a mapped property with the same name. That is, if B inherits from A then B