[BUGFIX] FLUIDTEMPLATE - Serialization of 'Closure' is not allowed tmaroschik/namespaced_master
authorOliver Hader <oliver@typo3.org>
Thu, 3 May 2012 19:27:03 +0000 (21:27 +0200)
committerBenjamin Mack <benni@typo3.org>
Mon, 16 Jul 2012 08:45:10 +0000 (10:45 +0200)
When using FLUIDTEMPLATE and COA_INT or USER_INT on the same
level and partials are used in the Fluid template, then there
will be Closures. COA_INT and USER_INT are going to serialize
the cObj, which fails when a Closure shall be processed.

Since the Closures have been collected in $cObj->contentObjects
the fix is to use a cloned version of the cObj which does not
contain these contentObjects anymore for COA_INT and USER_INT.

Change-Id: I5c1f9b01caef1df5077955bd7fa6e879e41ca854
Fixes: #36820
Related: #32295
Releases: 6.0, 4.7, 4.6
Reviewed-on: http://review.typo3.org/10979
Reviewed-by: Susanne Moog
Tested-by: Susanne Moog
Reviewed-by: Helmut Hummel
Tested-by: Helmut Hummel
Reviewed-by: Benjamin Mack
Tested-by: Benjamin Mack
typo3/sysext/cms/tslib/class.tslib_content.php

index 384bf68..7dce1c3 100644 (file)
@@ -476,6 +476,31 @@ class tslib_cObj {
        }
 
        /**
+        * Serialization (sleep) helper.
+        *
+        * Removes properties of this object from serialization.
+        * This action is necessary, since there might be closures used
+        * in the accordant content objects (e.g. in FLUIDTEMPLATE) which
+        * cannot be serialized. It's fine to reset $this->contentObjects
+        * since elements will be recreated and are just a local cache,
+        * but not required for runtime logic and behaviour.
+        *
+        * @return array Names of the properties to be serialized
+        * @see http://forge.typo3.org/issues/36820
+        */
+       public function __sleep() {
+                       // Use get_objects_vars() instead of
+                       // a much more expensive Reflection:
+               $properties = get_object_vars($this);
+
+               if (isset($properties['contentObjects'])) {
+                       unset($properties['contentObjects']);
+               }
+
+               return array_keys($properties);
+       }
+
+       /**
         * Gets the 'getImgResource' hook objects.
         * The first call initializes the accordant objects.
         *
@@ -8158,4 +8183,4 @@ class tslib_cObj {
                }
        }
 }
-?>
\ No newline at end of file
+?>