function AbstractCloner::castObject
Casts an object to an array representation.
Parameters
bool $isNested True if the object is nested in the dumped structure:
1 call to AbstractCloner::castObject()
- VarCloner::doClone in vendor/
symfony/ var-dumper/ Cloner/ VarCloner.php - Effectively clones the PHP variable.
File
-
vendor/
symfony/ var-dumper/ Cloner/ AbstractCloner.php, line 331
Class
- AbstractCloner
- AbstractCloner implements a generic caster mechanism for objects and resources.
Namespace
Symfony\Component\VarDumper\ClonerCode
protected function castObject(Stub $stub, bool $isNested) : array {
$obj = $stub->value;
$class = $stub->class;
if (str_contains($class, "@anonymous\x00")) {
$stub->class = get_debug_type($obj);
}
if (isset($this->classInfo[$class])) {
[
$i,
$parents,
$hasDebugInfo,
$fileInfo,
] = $this->classInfo[$class];
}
else {
$i = 2;
$parents = [
$class,
];
$hasDebugInfo = method_exists($class, '__debugInfo');
foreach (class_parents($class) as $p) {
$parents[] = $p;
++$i;
}
foreach (class_implements($class) as $p) {
$parents[] = $p;
++$i;
}
$parents[] = '*';
$r = new \ReflectionClass($class);
$fileInfo = $r->isInternal() || $r->isSubclassOf(Stub::class) ? [] : [
'file' => $r->getFileName(),
'line' => $r->getStartLine(),
];
$this->classInfo[$class] = [
$i,
$parents,
$hasDebugInfo,
$fileInfo,
];
}
$stub->attr += $fileInfo;
$a = Caster::castObject($obj, $class, $hasDebugInfo, $stub->class);
try {
while ($i--) {
if (!empty($this->casters[$p = $parents[$i]])) {
foreach ($this->casters[$p] as $callback) {
$a = $callback($obj, $a, $stub, $isNested, $this->filter);
}
}
}
} catch (\Exception $e) {
$a = [
(Stub::TYPE_OBJECT === $stub->type ? Caster::PREFIX_VIRTUAL : '') . '⚠' => new ThrowingCasterException($e),
] + $a;
}
return $a;
}