Skip to content

Instantly share code, notes, and snippets.

@iggyvolz
Created October 10, 2019 16:35
Show Gist options
  • Save iggyvolz/5061fe63090588d0f4f96874380b5ef3 to your computer and use it in GitHub Desktop.
Save iggyvolz/5061fe63090588d0f4f96874380b5ef3 to your computer and use it in GitHub Desktop.
FQSEN resolution failure
<?php
namespace foo{
class y
{
}
}
namespace bar{
use foo\y;
use phpDocumentor\Reflection\Types\ContextFactory;
use phpDocumentor\Reflection\DocBlockFactory;
use ReflectionClass;
require_once "vendor/autoload.php";
/**
* @property y $bin
*/
class z
{
}
$docblockfactory = DocBlockFactory::createInstance();
$contextfactory = new ContextFactory();
$x = new /** @property y $bin */ class {
};
$y = new z();
// This works:
$reflectionClass = new ReflectionClass(get_class($y));
$context = $contextfactory->createFromReflector($reflectionClass);
$docblock = $docblockfactory->create($reflectionClass, $context);
/*
* Fails with:
* PHP Fatal error: Uncaught InvalidArgumentException: "\class@anonymous in vendor\phpdocumentor\reflection-common\src\Fqsen.php:51
* Stack trace:
* #0 vendor\phpdocumentor\type-resolver\src\FqsenResolver.php(67): phpDocumentor\Reflection\Fqsen->__construct('\\class@anonymou...')
* #1 vendor\phpdocumentor\type-resolver\src\FqsenResolver.php(37): phpDocumentor\Reflection\FqsenResolver->resolvePartialStructuralElementName('y', Object(phpDocumentor\Reflection\Types\Context))
* #2 vendor\phpdocumentor\type-resolver\src\TypeResolver.php(384): phpDocumentor\Reflection\FqsenResolver->resolve('y', Object(phpDocumentor\Reflection\Types\Context))
* #3 vendor\phpdocumentor\type-resolver\src\TypeResolver.php(291): phpDocumentor\Reflection\TypeResolver->resolveTypedObject('y', Object(phpDocumentor\Reflection\Types\Context))
* #4 vendor\phpdocumentor\typ in vendor\phpdocumentor\reflection-common\src\Fqsen.php on line 51
*/
$reflectionClass = new ReflectionClass(get_class($x));
$context = $contextfactory->createFromReflector($reflectionClass);
$docblock = $docblockfactory->create($reflectionClass, $context);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment