Skip to content
This repository
Browse code

Enabled Debugger::exportVar() to display private & protected properties.

This will only work in PHP >= 5.3. Patch originally created
by 'dereuromark'.
  • Loading branch information...
commit 57c495f53a63b92fe2766f03d6f20754f79be31d 1 parent 8931b74
Mark Story authored August 06, 2012
35  lib/Cake/Test/Case/Utility/DebuggerTest.php
@@ -325,8 +325,43 @@ public function testExportVar() {
325 325
 	elementCacheSettings => array()
326 326
 	int => (int) 2
327 327
 	float => (float) 1.333
  328
+
  329
+TEXT;
  330
+		if (version_compare(PHP_VERSION, '5.3.0') >= 0) {
  331
+			$expected .= <<<TEXT
  332
+	[protected] _passedVars => array(
  333
+		(int) 0 => 'viewVars',
  334
+		(int) 1 => 'autoLayout',
  335
+		(int) 2 => 'ext',
  336
+		(int) 3 => 'helpers',
  337
+		(int) 4 => 'view',
  338
+		(int) 5 => 'layout',
  339
+		(int) 6 => 'name',
  340
+		(int) 7 => 'theme',
  341
+		(int) 8 => 'layoutPath',
  342
+		(int) 9 => 'viewPath',
  343
+		(int) 10 => 'request',
  344
+		(int) 11 => 'plugin',
  345
+		(int) 12 => 'passedArgs',
  346
+		(int) 13 => 'cacheAction'
  347
+	)
  348
+	[protected] _scripts => array()
  349
+	[protected] _paths => array()
  350
+	[protected] _helpersLoaded => false
  351
+	[protected] _parents => array()
  352
+	[protected] _current => null
  353
+	[protected] _currentType => ''
  354
+	[protected] _stack => array()
  355
+	[protected] _eventManager => object(CakeEventManager) {}
  356
+	[protected] _eventManagerConfigured => false
  357
+	[private] __viewFileName => null
  358
+
  359
+TEXT;
  360
+		}
  361
+		$expected .= <<<TEXT
328 362
 }
329 363
 TEXT;
  364
+
330 365
 		$this->assertTextEquals($expected, $result);
331 366
 
332 367
 		$data = array(
25  lib/Cake/Utility/Debugger.php
@@ -576,6 +576,31 @@ protected static function _object($var, $depth, $indent) {
576 576
 				$value = self::_export($value, $depth - 1, $indent);
577 577
 				$props[] = "$key => " . $value;
578 578
 			}
  579
+
  580
+			if (version_compare(PHP_VERSION, '5.3.0') >= 0) {
  581
+				$ref = new ReflectionObject($var);
  582
+
  583
+				$reflectionProperties = $ref->getProperties(ReflectionProperty::IS_PROTECTED);
  584
+				foreach ($reflectionProperties as $reflectionProperty) {
  585
+					$reflectionProperty->setAccessible(true);
  586
+					$property = $reflectionProperty->getValue($var);
  587
+
  588
+					$value = self::_export($property, $depth - 1, $indent);
  589
+					$key = $reflectionProperty->name;
  590
+					$props[] = "[protected] $key => " . $value;
  591
+				}
  592
+
  593
+				$reflectionProperties = $ref->getProperties(ReflectionProperty::IS_PRIVATE);
  594
+				foreach ($reflectionProperties as $reflectionProperty) {
  595
+					$reflectionProperty->setAccessible(true);
  596
+					$property = $reflectionProperty->getValue($var);
  597
+
  598
+					$value = self::_export($property, $depth - 1, $indent);
  599
+					$key = $reflectionProperty->name;
  600
+					$props[] = "[private] $key => " . $value;
  601
+				}
  602
+			}
  603
+
579 604
 			$out .= $break . implode($break, $props) . $end;
580 605
 		}
581 606
 		$out .= '}';

0 notes on commit 57c495f

Please sign in to comment.
Something went wrong with that request. Please try again.