MediaWiki master
DumpUtils.php
Go to the documentation of this file.
1<?php
2
3namespace Wikimedia\DebugInfo;
4
8class DumpUtils {
18 public static function objectToArray( $object ) {
19 $vars = (array)$object;
20 $class = new \ReflectionClass( $object );
21 while ( $class ) {
22 foreach ( $class->getProperties() as $property ) {
23 if ( AnnotationReader::propertyHasAnnotation( $property, 'noVarDump' ) ) {
24 // Ref: zend_declare_typed_property(), zend_mangle_property_name()
25 if ( $property->isPrivate() ) {
26 $mangledName = "\0{$class->name}\0{$property->name}";
27 } elseif ( $property->isProtected() ) {
28 $mangledName = "\0*\0{$property->name}";
29 } else {
30 $mangledName = $property->name;
31 }
32 if ( isset( $vars[$mangledName] ) && !is_scalar( $vars[$mangledName] ) ) {
33 $vars[$mangledName] = new Placeholder( $vars[$mangledName] );
34 }
35 }
36 }
37 $class = $class->getParentClass();
38 }
39 return $vars;
40 }
41}
static propertyHasAnnotation(\ReflectionProperty $property, string $annotationName)
Determine whether a ReflectionProperty has a specified annotation.
static objectToArray( $object)
Convert an object to an array by casting, but filter the properties to make recursive dumping more fe...
Definition DumpUtils.php:18
A class used for replacing large objects in var_dump() output.