Skip to content

[VarExporter] foreach() argument must be of type array|object, string given, ClassNotFoundException #51010

@vudaltsov

Description

@vudaltsov

Symfony version(s) affected

6.3.0

Description

I get these errors when using Symfony VarExporter on PHP 8.2.8.

PHP Warning:  foreach() argument must be of type array|object, string given in /vendor/symfony/var-exporter/VarExporter.php on line 100
PHP Stack trace:
PHP   1. {main}() /index.php:0
PHP   2. Symfony\Component\VarExporter\VarExporter::export($value = class A { public string $x = 'a'; public array $y = [0 => class A { ... }] }, $isStaticValue = *uninitialized*, $foundClasses = *uninitialized*) /index.php:25

Warning: foreach() argument must be of type array|object, string given in /vendor/symfony/var-exporter/VarExporter.php on line 100

Call Stack:
    0.0009     354480   1. {main}() /index.php:0
    0.2091     785312   2. Symfony\Component\VarExporter\VarExporter::export($value = class A { public string $x = 'a'; public array $y = [0 => class A { ... }] }, $isStaticValue = ???, $foundClasses = ???) /index.php:25

PHP Warning:  foreach() argument must be of type array|object, string given in /vendor/symfony/var-exporter/VarExporter.php on line 100
PHP Stack trace:
PHP   1. {main}() /index.php:0
PHP   2. Symfony\Component\VarExporter\VarExporter::export($value = class A { public string $x = 'a'; public array $y = [0 => class A { ... }] }, $isStaticValue = *uninitialized*, $foundClasses = *uninitialized*) /index.php:25

Warning: foreach() argument must be of type array|object, string given in /vendor/symfony/var-exporter/VarExporter.php on line 100

Call Stack:
    0.0009     354480   1. {main}() /index.php:0
    0.2091     785312   2. Symfony\Component\VarExporter\VarExporter::export($value = class A { public string $x = 'a'; public array $y = [0 => class A { ... }] }, $isStaticValue = ???, $foundClasses = ???) /index.php:25

PHP Fatal error:  Uncaught Symfony\Component\VarExporter\Exception\ClassNotFoundException: Class "y" not found. in /vendor/symfony/var-exporter/Internal/Hydrator.php:99
Stack trace:
#0 /vendor/symfony/var-exporter/Internal/Hydrator.php(45): Symfony\Component\VarExporter\Internal\Hydrator::getHydrator('y')
#1 /index.php(27) : eval()'d code(1): Symfony\Component\VarExporter\Internal\Hydrator::hydrate(Array, NULL, Array, Object(A), Array)
#2 /index.php(27): eval()
#3 {main}
  thrown in /vendor/symfony/var-exporter/Internal/Hydrator.php on line 99

Fatal error: Uncaught Symfony\Component\VarExporter\Exception\ClassNotFoundException: Class "y" not found. in /vendor/symfony/var-exporter/Internal/Hydrator.php on line 99

Symfony\Component\VarExporter\Exception\ClassNotFoundException: Class "y" not found. in /vendor/symfony/var-exporter/Internal/Hydrator.php on line 99

Call Stack:
    0.0009     354480   1. {main}() /index.php:0
    0.2176     791632   2. eval('/index.php(27) : eval()'d code') /index.php:27
    0.2176     792848   3. Symfony\Component\VarExporter\Internal\Hydrator::hydrate($objects = [0 => class A { public string $x = *uninitialized*; public array $y = *uninitialized* }, 1 => class A { public string $x = *uninitialized*; public array $y = *uninitialized* }], $values = NULL, $properties = ['y' => [0 => [...]]], $value = class A { public string $x = *uninitialized*; public array $y = *uninitialized* }, $wakeups = []) /index.php(27) : eval()'d code:1
    0.2176     792896   4. Symfony\Component\VarExporter\Internal\Hydrator::getHydrator($class = 'y') /vendor/symfony/var-exporter/Internal/Hydrator.php:45

How to reproduce

<?php

use Symfony\Component\VarExporter\VarExporter;

require_once __DIR__.'/vendor/autoload.php';

final class A
{
    public function __construct(
        public string $x,
        public array $y,
    ) {
    }

    public function __serialize(): array
    {
        return [
            'x' => $this->x,
            'y' => $this->y,
        ];
    }
}

$value = new A('a', [new A('b', [])]);
$exported = VarExporter::export($value);

eval("return {$exported};");

Possible Solution

No response

Additional Context

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy