This repository was archived by the owner on Jun 24, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 43
This repository was archived by the owner on Jun 24, 2025. It is now read-only.
Fatal error: Trait method "x" was already imported. #71
Copy link
Copy link
Open
Description
Example:
TraitA.php
<?php
namespace T;
trait TraitA
{
abstract public function x();
}TraitB.php
<?php
namespace T;
trait TraitB
{
abstract public function x();
}TraitAggregate.php
<?php
namespace T;
trait TraitAggregate
{
use TraitA, TraitB;
}T.php
<?php
namespace T;
class T
{
use TraitAggregate;
public function x() {
echo "foo";
}
}And test.php:
<?php
use TokenReflection\Broker;
require 'vendor/autoload.php';
$t = new \T\T();
$t->x();
$broker = new Broker(new Broker\Backend\Memory());
$broker->processDirectory('./src');
$class = $broker->getClass('T\T');
var_dump($class->getMethods());Result:
% php ./test.php
fooPHP Fatal error: Uncaught exception 'TokenReflection\Exception\RuntimeException' with message 'Trait method "x" was already imported.' in /home/popsul/projects/traits/vendor/andrewsville/php-token-reflection/TokenReflection/ReflectionClass.php on line 734
Thrown when working with "T\TraitAggregate".
Stack trace:
#0 /home/popsul/projects/traits/vendor/andrewsville/php-token-reflection/TokenReflection/ReflectionClass.php(607): TokenReflection\ReflectionClass->getTraitMethods()
#1 /home/popsul/projects/traits/vendor/andrewsville/php-token-reflection/TokenReflection/ReflectionClass.php(701): TokenReflection\ReflectionClass->getMethods(NULL)
#2 /home/popsul/projects/traits/vendor/andrewsville/php-token-reflection/TokenReflection/ReflectionClass.php(607): TokenReflection\ReflectionClass->getTraitMethods()
#3 /home/popsul/projects/traits/test.php(14): TokenReflection\ReflectionClass->getMethods()
#4 {main}
thrown in /home/popsul/projects/traits/vendor/andrewsville/php-token-reflection/TokenReflection/ReflectionClass.php on line 734
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels