Skip to content

Reflection error after upgrading to 0.12.28 #3463

@emodric

Description

@emodric

Bug report

I'm trying to write a class that supports both Symfony Contracts event and legacy event from Syfmony 3.x. PHPStan reports the following error when running on Symfony 5 where Symfony\Component\EventDispatcher\Event is not present:

 ------ ---------------------------------------------------------------------- 
  Line   MyEvent.php                              
 ------ ---------------------------------------------------------------------- 
         Reflection error: Symfony\Component\EventDispatcher\Event not found.  
  22     Reflection error: Symfony\Component\EventDispatcher\Event not found.  
  22     Reflection error: Symfony\Component\EventDispatcher\Event not found.  
  22     Reflection error: Symfony\Component\EventDispatcher\Event not found.  
  29     Reflection error: Symfony\Component\EventDispatcher\Event not found.  
  29     Reflection error: Symfony\Component\EventDispatcher\Event not found.  
  29     Reflection error: Symfony\Component\EventDispatcher\Event not found.  
  29     Reflection error: Symfony\Component\EventDispatcher\Event not found.  
  31     Reflection error: Symfony\Component\EventDispatcher\Event not found.  
  31     Reflection error: Symfony\Component\EventDispatcher\Event not found.  
  31     Reflection error: Symfony\Component\EventDispatcher\Event not found.  
  31     Reflection error: Symfony\Component\EventDispatcher\Event not found.  
  31     Reflection error: Symfony\Component\EventDispatcher\Event not found.  
 ------ ---------------------------------------------------------------------- 

Code snippet that reproduces the problem

<?php

declare(strict_types=1);

namespace App;

use Symfony\Component\EventDispatcher\Event as LegacyEvent;
use Symfony\Contracts\EventDispatcher\Event as ContractsEvent;

if (class_exists(ContractsEvent::class)) {
    abstract class Event extends ContractsEvent
    {
    }
} elseif (class_exists(LegacyEvent::class)) {
    abstract class Event extends LegacyEvent
    {
    }
}

final class MyEvent extends Event
{
    // ...
}

However, I can't seem to reproduce this in the playground: https://phpstan.org/r/e812ed4d-2759-46d0-bee1-c589d7c4fca2

Expected output

No errors should be reported as in 0.12.25

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions