Function use statement in a class
I'm getting the following error:
Fatal error: Uncaught AssertionError: assert(in_array($token[0], [T_NAME_FULLY_QUALIFIED, T_NAME_QUALIFIED, T_STRING])) in /Users/x/sites/x/vendor/eventsauce/object-hydrator/src/NaivePropertyTypeResolver.php:89
To reproduce:
<?php
use EventSauce\ObjectHydrator\ObjectMapperUsingReflection;
require __DIR__.'/../vendor/autoload.php';
class FooBar
{
public function __construct(array $foo)
{
//
}
}
$data = [
'foo' => ['bar', 'baz'],
];
$object = (new ObjectMapperUsingReflection())->hydrateObject(FooBar::class, $data);
$unused = function () use ($data)
{
//
};
dd($object);
Using version 1.4.0
I believe this is happening because when you use array as a type it will resolveUseStatementMap
https://github.com/EventSaucePHP/ObjectHydrator/blob/89af85d58355477597d94a066818ee828058c3af/src/NaivePropertyTypeResolver.php#L50 (see if statement above)
And because there is another use in the $unused function in my code it errors because it thinks it's an import.
I think it should stop looking for imports when inside a class. I think I'll be able to fix this but first wanted to know if there is another (preferred) solution.
PS: I know side effects are not standard in PHP, but this was just for an example, it doesn't matter where the (function) use is, might also be in another method on the class