avoid using Reflection for some classes
if a class has problems with Reflection, then fall back to the old toArray method of counting its properties. For example, using reflection on an ext-protobuf Message causes a segfault
This commit is contained in:
parent
507d2333cb
commit
1e4815983a
|
|
@ -33,6 +33,7 @@ use function str_replace;
|
|||
use function strtr;
|
||||
use function var_export;
|
||||
use BackedEnum;
|
||||
use Google\Protobuf\Internal\Message;
|
||||
use ReflectionObject;
|
||||
use SebastianBergmann\RecursionContext\Context as RecursionContext;
|
||||
use SplObjectStorage;
|
||||
|
|
@ -129,7 +130,9 @@ final readonly class Exporter
|
|||
}
|
||||
|
||||
if (is_object($value)) {
|
||||
$numberOfProperties = count((new ReflectionObject($value))->getProperties());
|
||||
$numberOfProperties = $this->cannotUseReflection($value)
|
||||
? count($this->toArray($value))
|
||||
: count((new ReflectionObject($value))->getProperties());
|
||||
|
||||
return sprintf(
|
||||
'%s Object (%s)',
|
||||
|
|
@ -393,4 +396,9 @@ final readonly class Exporter
|
|||
|
||||
return $class . ' Object #' . spl_object_id($value) . ' (' . $buffer . ')';
|
||||
}
|
||||
|
||||
private function cannotUseReflection(object $object): bool
|
||||
{
|
||||
return $object instanceof Message;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue