[BUGFIX] FLUIDTEMPLATE - Serialization of 'Closure' is not allowed
authorOliver Hader <oliver@typo3.org>
Thu, 3 May 2012 19:27:03 +0000 (21:27 +0200)
committerXavier Perseguers <xavier@typo3.org>
Tue, 16 Oct 2012 08:49:08 +0000 (10:49 +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: I03dada20a133474f5260d432cbf75fd29c2b11e7
Fixes: #36820
Related: #32295
Releases: 6.0, 4.7, 4.6
Reviewed-on: http://review.typo3.org/13897
Reviewed-by: Stefan Neufeind
Reviewed-by: Xavier Perseguers
Tested-by: Xavier Perseguers
typo3/sysext/cms/tslib/class.tslib_content.php

index 7691970..7855c74 100644 (file)
@@ -453,6 +453,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.
         *
@@ -7896,8 +7921,6 @@ class tslib_cObj {
        }
 }
 
-
-
 /**
  * Rendering of framesets
  *
@@ -8261,7 +8284,6 @@ class tslib_controlTable {
        }
 }
 
-
 if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['tslib/class.tslib_content.php'])) {
        include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['tslib/class.tslib_content.php']);
 }