Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crash / Infinite loop when target class constructor accepts self #541

Open
mpesari opened this issue May 16, 2024 · 2 comments
Open

Crash / Infinite loop when target class constructor accepts self #541

mpesari opened this issue May 16, 2024 · 2 comments

Comments

@mpesari
Copy link
Contributor

mpesari commented May 16, 2024

Hi, stumbled into this:

<?php declare(strict_types=1);

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

class Test {
    public function __construct(string|self $value) {
        // copy-constructor-ish
    }
}

$mapper = (new CuyZ\Valinor\MapperBuilder)->mapper();

$test = $mapper->map(Test::class, ['value' => 'foo']); // string -> OK

$test = $mapper->map(Test::class, ['value' => $test]); // self -> OK

$test = $mapper->map(Test::class, ['value' => null]); // null -> FAIL
$ php test.php
PHP Fatal error:  Uncaught Error: Xdebug has detected a possible infinite loop, and aborted your script ...

Without Xdebug it just keeps running.

@kevariable
Copy link

you'd need string | self | null

@mpesari
Copy link
Contributor Author

mpesari commented Oct 4, 2024

Let me clarify:

What is expected to happen?

Because null is not allowed as $value, the mapper is expected to throw MappingError.

This is what happens if self is removed from allowed types:

Uncaught CuyZ\Valinor\Mapper\TypeTreeMapperError: Could not map type `Test`. An error occurred at path value: Value null is not a valid string.

What actually happens?

The library enters infinite loop/recursion.

Program crashes when either time limit or memory limit is reached.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants