comparison vendor/symfony/var-dumper/Cloner/VarCloner.php @ 17:129ea1e6d783

Update, including to Drupal core 8.6.10
author Chris Cannam
date Thu, 28 Feb 2019 13:21:36 +0000
parents 7a779792577d
children af1871eacc83
comparison
equal deleted inserted replaced
16:c2387f117808 17:129ea1e6d783
17 class VarCloner extends AbstractCloner 17 class VarCloner extends AbstractCloner
18 { 18 {
19 private static $gid; 19 private static $gid;
20 private static $hashMask = 0; 20 private static $hashMask = 0;
21 private static $hashOffset = 0; 21 private static $hashOffset = 0;
22 private static $arrayCache = array(); 22 private static $arrayCache = [];
23 23
24 /** 24 /**
25 * {@inheritdoc} 25 * {@inheritdoc}
26 */ 26 */
27 protected function doClone($var) 27 protected function doClone($var)
28 { 28 {
29 $len = 1; // Length of $queue 29 $len = 1; // Length of $queue
30 $pos = 0; // Number of cloned items past the minimum depth 30 $pos = 0; // Number of cloned items past the minimum depth
31 $refsCounter = 0; // Hard references counter 31 $refsCounter = 0; // Hard references counter
32 $queue = array(array($var)); // This breadth-first queue is the return value 32 $queue = [[$var]]; // This breadth-first queue is the return value
33 $indexedArrays = array(); // Map of queue indexes that hold numerically indexed arrays 33 $indexedArrays = []; // Map of queue indexes that hold numerically indexed arrays
34 $hardRefs = array(); // Map of original zval hashes to stub objects 34 $hardRefs = []; // Map of original zval hashes to stub objects
35 $objRefs = array(); // Map of original object handles to their stub object couterpart 35 $objRefs = []; // Map of original object handles to their stub object counterpart
36 $resRefs = array(); // Map of original resource handles to their stub object couterpart 36 $resRefs = []; // Map of original resource handles to their stub object counterpart
37 $values = array(); // Map of stub objects' hashes to original values 37 $values = []; // Map of stub objects' hashes to original values
38 $maxItems = $this->maxItems; 38 $maxItems = $this->maxItems;
39 $maxString = $this->maxString; 39 $maxString = $this->maxString;
40 $minDepth = $this->minDepth; 40 $minDepth = $this->minDepth;
41 $currentDepth = 0; // Current tree depth 41 $currentDepth = 0; // Current tree depth
42 $currentDepthFinalIndex = 0; // Final $queue index for current tree depth 42 $currentDepthFinalIndex = 0; // Final $queue index for current tree depth
43 $minimumDepthReached = 0 === $minDepth; // Becomes true when minimum tree depth has been reached 43 $minimumDepthReached = 0 === $minDepth; // Becomes true when minimum tree depth has been reached
44 $cookie = (object) array(); // Unique object used to detect hard references 44 $cookie = (object) []; // Unique object used to detect hard references
45 $a = null; // Array cast for nested structures 45 $a = null; // Array cast for nested structures
46 $stub = null; // Stub capturing the main properties of an original item value 46 $stub = null; // Stub capturing the main properties of an original item value
47 // or null if the original value is used directly 47 // or null if the original value is used directly
48 48
49 if (!self::$hashMask) { 49 if (!self::$hashMask) {
72 // see https://wiki.php.net/rfc/convert_numeric_keys_in_object_array_casts 72 // see https://wiki.php.net/rfc/convert_numeric_keys_in_object_array_casts
73 foreach ($vals as $k => $v) { 73 foreach ($vals as $k => $v) {
74 if (\is_int($k)) { 74 if (\is_int($k)) {
75 continue; 75 continue;
76 } 76 }
77 foreach (array($k => true) as $gk => $gv) { 77 foreach ([$k => true] as $gk => $gv) {
78 } 78 }
79 if ($gk !== $k) { 79 if ($gk !== $k) {
80 $fromObjCast = true; 80 $fromObjCast = true;
81 $refs = $vals = \array_values($queue[$i]); 81 $refs = $vals = \array_values($queue[$i]);
82 break; 82 break;
161 $a[$gid] = true; 161 $a[$gid] = true;
162 162
163 // Happens with copies of $GLOBALS 163 // Happens with copies of $GLOBALS
164 if (isset($v[$gid])) { 164 if (isset($v[$gid])) {
165 unset($v[$gid]); 165 unset($v[$gid]);
166 $a = array(); 166 $a = [];
167 foreach ($v as $gk => &$gv) { 167 foreach ($v as $gk => &$gv) {
168 $a[$gk] = &$gv; 168 $a[$gk] = &$gv;
169 } 169 }
170 unset($gv); 170 unset($gv);
171 } else { 171 } else {
252 } 252 }
253 } 253 }
254 254
255 if ($arrayStub === $stub) { 255 if ($arrayStub === $stub) {
256 if ($arrayStub->cut) { 256 if ($arrayStub->cut) {
257 $stub = array($arrayStub->cut, $arrayStub->class => $arrayStub->position); 257 $stub = [$arrayStub->cut, $arrayStub->class => $arrayStub->position];
258 $arrayStub->cut = 0; 258 $arrayStub->cut = 0;
259 } elseif (isset(self::$arrayCache[$arrayStub->class][$arrayStub->position])) { 259 } elseif (isset(self::$arrayCache[$arrayStub->class][$arrayStub->position])) {
260 $stub = self::$arrayCache[$arrayStub->class][$arrayStub->position]; 260 $stub = self::$arrayCache[$arrayStub->class][$arrayStub->position];
261 } else { 261 } else {
262 self::$arrayCache[$arrayStub->class][$arrayStub->position] = $stub = array($arrayStub->class => $arrayStub->position); 262 self::$arrayCache[$arrayStub->class][$arrayStub->position] = $stub = [$arrayStub->class => $arrayStub->position];
263 } 263 }
264 } 264 }
265 265
266 if ($zvalIsRef) { 266 if ($zvalIsRef) {
267 $refs[$k]->value = $stub; 267 $refs[$k]->value = $stub;
271 } 271 }
272 272
273 if ($fromObjCast) { 273 if ($fromObjCast) {
274 $fromObjCast = false; 274 $fromObjCast = false;
275 $refs = $vals; 275 $refs = $vals;
276 $vals = array(); 276 $vals = [];
277 $j = -1; 277 $j = -1;
278 foreach ($queue[$i] as $k => $v) { 278 foreach ($queue[$i] as $k => $v) {
279 foreach (array($k => true) as $gk => $gv) { 279 foreach ([$k => true] as $gk => $gv) {
280 } 280 }
281 if ($gk !== $k) { 281 if ($gk !== $k) {
282 $vals = (object) $vals; 282 $vals = (object) $vals;
283 $vals->{$k} = $refs[++$j]; 283 $vals->{$k} = $refs[++$j];
284 $vals = (array) $vals; 284 $vals = (array) $vals;
298 return $queue; 298 return $queue;
299 } 299 }
300 300
301 private static function initHashMask() 301 private static function initHashMask()
302 { 302 {
303 $obj = (object) array(); 303 $obj = (object) [];
304 self::$hashOffset = 16 - PHP_INT_SIZE; 304 self::$hashOffset = 16 - PHP_INT_SIZE;
305 self::$hashMask = -1; 305 self::$hashMask = -1;
306 306
307 if (defined('HHVM_VERSION')) { 307 if (\defined('HHVM_VERSION')) {
308 self::$hashOffset += 16; 308 self::$hashOffset += 16;
309 } else { 309 } else {
310 // check if we are nested in an output buffering handler to prevent a fatal error with ob_start() below 310 // check if we are nested in an output buffering handler to prevent a fatal error with ob_start() below
311 $obFuncs = array('ob_clean', 'ob_end_clean', 'ob_flush', 'ob_end_flush', 'ob_get_contents', 'ob_get_flush'); 311 $obFuncs = ['ob_clean', 'ob_end_clean', 'ob_flush', 'ob_end_flush', 'ob_get_contents', 'ob_get_flush'];
312 foreach (debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS) as $frame) { 312 foreach (debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS) as $frame) {
313 if (isset($frame['function'][0]) && !isset($frame['class']) && 'o' === $frame['function'][0] && in_array($frame['function'], $obFuncs)) { 313 if (isset($frame['function'][0]) && !isset($frame['class']) && 'o' === $frame['function'][0] && \in_array($frame['function'], $obFuncs)) {
314 $frame['line'] = 0; 314 $frame['line'] = 0;
315 break; 315 break;
316 } 316 }
317 } 317 }
318 if (!empty($frame['line'])) { 318 if (!empty($frame['line'])) {