Localisation updates from https://translatewiki.net.
[mediawiki.git] / includes / libs / DebugInfo / DumpUtils.php
blobac3f1286348b84dc8abfc17634875cb5d92d5c50
1 <?php
3 namespace Wikimedia\DebugInfo;
5 /**
6 * @since 1.40
7 */
8 class DumpUtils {
9 /**
10 * Convert an object to an array by casting, but filter the properties
11 * to make recursive dumping more feasible.
13 * phpcs:ignore MediaWiki.Commenting.FunctionComment.ObjectTypeHintParam
14 * @param object $object
15 * @return array
16 * @throws \ReflectionException
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;
32 if ( isset( $vars[$mangledName] ) && !is_scalar( $vars[$mangledName] ) ) {
33 $vars[$mangledName] = new Placeholder( $vars[$mangledName] );
37 $class = $class->getParentClass();
39 return $vars;