Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

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
@markstory markstory authored
View
35 lib/Cake/Test/Case/Utility/DebuggerTest.php
@@ -325,8 +325,43 @@ public function testExportVar() {
elementCacheSettings => array()
int => (int) 2
float => (float) 1.333
+
+TEXT;
+ if (version_compare(PHP_VERSION, '5.3.0') >= 0) {
+ $expected .= <<<TEXT
+ [protected] _passedVars => array(
+ (int) 0 => 'viewVars',
+ (int) 1 => 'autoLayout',
+ (int) 2 => 'ext',
+ (int) 3 => 'helpers',
+ (int) 4 => 'view',
+ (int) 5 => 'layout',
+ (int) 6 => 'name',
+ (int) 7 => 'theme',
+ (int) 8 => 'layoutPath',
+ (int) 9 => 'viewPath',
+ (int) 10 => 'request',
+ (int) 11 => 'plugin',
+ (int) 12 => 'passedArgs',
+ (int) 13 => 'cacheAction'
+ )
+ [protected] _scripts => array()
+ [protected] _paths => array()
+ [protected] _helpersLoaded => false
+ [protected] _parents => array()
+ [protected] _current => null
+ [protected] _currentType => ''
+ [protected] _stack => array()
+ [protected] _eventManager => object(CakeEventManager) {}
+ [protected] _eventManagerConfigured => false
+ [private] __viewFileName => null
+
+TEXT;
+ }
+ $expected .= <<<TEXT
}
TEXT;
+
$this->assertTextEquals($expected, $result);
$data = array(
View
25 lib/Cake/Utility/Debugger.php
@@ -576,6 +576,31 @@ protected static function _object($var, $depth, $indent) {
$value = self::_export($value, $depth - 1, $indent);
$props[] = "$key => " . $value;
}
+
+ if (version_compare(PHP_VERSION, '5.3.0') >= 0) {
+ $ref = new ReflectionObject($var);
+
+ $reflectionProperties = $ref->getProperties(ReflectionProperty::IS_PROTECTED);
+ foreach ($reflectionProperties as $reflectionProperty) {
+ $reflectionProperty->setAccessible(true);
+ $property = $reflectionProperty->getValue($var);
+
+ $value = self::_export($property, $depth - 1, $indent);
+ $key = $reflectionProperty->name;
+ $props[] = "[protected] $key => " . $value;
+ }
+
+ $reflectionProperties = $ref->getProperties(ReflectionProperty::IS_PRIVATE);
+ foreach ($reflectionProperties as $reflectionProperty) {
+ $reflectionProperty->setAccessible(true);
+ $property = $reflectionProperty->getValue($var);
+
+ $value = self::_export($property, $depth - 1, $indent);
+ $key = $reflectionProperty->name;
+ $props[] = "[private] $key => " . $value;
+ }
+ }
+
$out .= $break . implode($break, $props) . $end;
}
$out .= '}';
Please sign in to comment.
Something went wrong with that request. Please try again.