Skip to content

Running a downloaded phpstan phar with checkMissingOverrideMethodAttribute set to true prints errors in the phpstan stubs. #11907

@Brezak

Description

@Brezak

Bug report

Steps to reproduce:

  1. Clone this repo https://github.com/Brezak/break-phpstan ( I tried to trigger this bug on a standalone file but wasn't successful ).
  2. Make sure to delete your PHPStan cache ( the bug occurs only when PHPStan is generating new cache files ).
  3. Run the PHPStan phar in the root of the repository.
  4. Observe 58 errors in PHPStan stubs
  5. Run the PHPStan phar in the root of the repository again.
  6. Observe no errors printed.

PHPStan will keep reporting no errors until you delete the cache files again or run a different PHPStan install (.e.g one added through composer). I have not been able to reproduce this issue when PHPStan is installed through composer.

The output when running with the -vvv flag
Note: Using configuration file <path to home>/Projects/break-phpstan/phpstan.neon.
Result cache not used because the cache file does not exist.
 1/1 [▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓] 100% 6 secs/6 secs

 Result cache is saved.
    -------------------------------------------------------------------------------------------------------------------------------------- 
  Line   ../../Downloads/phpstan.phar/stubs/ArrayObject.stub                                                                             
 ------ -------------------------------------------------------------------------------------------------------------------------------- 
  :79    Method ArrayObject::getIterator() overrides method IteratorAggregate::getIterator() but is missing the #[\Override] attribute.  
 ------ -------------------------------------------------------------------------------------------------------------------------------- 

 ------ -------------------------------------------------------------------------------------------------------------------------------- 
  Line   ../../Downloads/phpstan.phar/stubs/Exception.stub                                                                               
 ------ -------------------------------------------------------------------------------------------------------------------------------- 
  :50    Method Throwable::__toString() overrides method Stringable::__toString() but is missing the #[\Override] attribute.             
  :60    Method Exception::getMessage() overrides method Throwable::getMessage() but is missing the #[\Override] attribute.              
  :66    Method Exception::getCode() overrides method Throwable::getCode() but is missing the #[\Override] attribute.                    
  :72    Method Exception::getFile() overrides method Throwable::getFile() but is missing the #[\Override] attribute.                    
  :78    Method Exception::getLine() overrides method Throwable::getLine() but is missing the #[\Override] attribute.                    
  :84    Method Exception::getTrace() overrides method Throwable::getTrace() but is missing the #[\Override] attribute.                  
  :90    Method Exception::getPrevious() overrides method Throwable::getPrevious() but is missing the #[\Override] attribute.            
  :96    Method Exception::getTraceAsString() overrides method Throwable::getTraceAsString() but is missing the #[\Override] attribute.  
  :107   Method Error::getMessage() overrides method Throwable::getMessage() but is missing the #[\Override] attribute.                  
  :113   Method Error::getCode() overrides method Throwable::getCode() but is missing the #[\Override] attribute.                        
  :119   Method Error::getFile() overrides method Throwable::getFile() but is missing the #[\Override] attribute.                        
  :125   Method Error::getLine() overrides method Throwable::getLine() but is missing the #[\Override] attribute.                        
  :131   Method Error::getTrace() overrides method Throwable::getTrace() but is missing the #[\Override] attribute.                      
  :137   Method Error::getPrevious() overrides method Throwable::getPrevious() but is missing the #[\Override] attribute.                
  :143   Method Error::getTraceAsString() overrides method Throwable::getTraceAsString() but is missing the #[\Override] attribute.      
 ------ -------------------------------------------------------------------------------------------------------------------------------- 

 ------ --------------------------------------------------------------------------------------------------------------------------- 
  Line   ../../Downloads/phpstan.phar/stubs/SplObjectStorage.stub                                                                   
 ------ --------------------------------------------------------------------------------------------------------------------------- 
  :64    Method SplObjectStorage::offsetGet() overrides method ArrayAccess::offsetGet() but is missing the #[\Override] attribute.  
 ------ --------------------------------------------------------------------------------------------------------------------------- 

 ------ ------------------------------------------------------------------------------------------------------------------ 
  Line   ../../Downloads/phpstan.phar/stubs/WeakReference.stub                                                             
 ------ ------------------------------------------------------------------------------------------------------------------ 
  :33    Method WeakMap::offsetGet() overrides method ArrayAccess::offsetGet() but is missing the #[\Override] attribute.  
 ------ ------------------------------------------------------------------------------------------------------------------ 

 ------ ------------------------------------------------------------------------------------------------------------------------- 
  Line   ../../Downloads/phpstan.phar/stubs/ext-ds.stub                                                                           
 ------ ------------------------------------------------------------------------------------------------------------------------- 
  :47    Method Ds\Deque::copy() overrides method Ds\Collection::copy() but is missing the #[\Override] attribute.                
  :56    Method Ds\Deque::merge() overrides method Ds\Sequence::merge() but is missing the #[\Override] attribute.                
  :64    Method Ds\Deque::filter() overrides method Ds\Sequence::filter() but is missing the #[\Override] attribute.              
  :73    Method Ds\Deque::map() overrides method Ds\Sequence::map() but is missing the #[\Override] attribute.                    
  :80    Method Ds\Deque::reversed() overrides method Ds\Sequence::reversed() but is missing the #[\Override] attribute.          
  :87    Method Ds\Deque::slice() overrides method Ds\Sequence::slice() but is missing the #[\Override] attribute.                
  :110   Method Ds\Map::copy() overrides method Ds\Collection::copy() but is missing the #[\Override] attribute.                  
  :318   Method Ds\Map::toArray() overrides method Ds\Collection::toArray() but is missing the #[\Override] attribute.            
  :544   Method Ds\Vector::copy() overrides method Ds\Collection::copy() but is missing the #[\Override] attribute.               
  :551   Method Ds\Vector::reversed() overrides method Ds\Sequence::reversed() but is missing the #[\Override] attribute.         
  :558   Method Ds\Vector::slice() overrides method Ds\Sequence::slice() but is missing the #[\Override] attribute.               
  :566   Method Ds\Vector::sorted() overrides method Ds\Sequence::sorted() but is missing the #[\Override] attribute.             
  :574   Method Ds\Vector::filter() overrides method Ds\Sequence::filter() but is missing the #[\Override] attribute.             
  :583   Method Ds\Vector::map() overrides method Ds\Sequence::map() but is missing the #[\Override] attribute.                   
  :592   Method Ds\Vector::merge() overrides method Ds\Sequence::merge() but is missing the #[\Override] attribute.               
  :628   Method Ds\Set::copy() overrides method Ds\Collection::copy() but is missing the #[\Override] attribute.                  
  :749   Method Ds\Set::toArray() overrides method Ds\Collection::toArray() but is missing the #[\Override] attribute.            
  :789   Method Ds\Stack::copy() overrides method Ds\Collection::copy() but is missing the #[\Override] attribute.                
  :821   Method Ds\Stack::toArray() overrides method Ds\Collection::toArray() but is missing the #[\Override] attribute.          
  :843   Method Ds\Queue::copy() overrides method Ds\Collection::copy() but is missing the #[\Override] attribute.                
  :874   Method Ds\Queue::toArray() overrides method Ds\Collection::toArray() but is missing the #[\Override] attribute.          
  :888   Method Ds\PriorityQueue::copy() overrides method Ds\Collection::copy() but is missing the #[\Override] attribute.        
  :919   Method Ds\PriorityQueue::toArray() overrides method Ds\Collection::toArray() but is missing the #[\Override] attribute.  
 ------ ------------------------------------------------------------------------------------------------------------------------- 

 ------ ----------------------------------------------------------------------------------------------------------------------------- 
  Line   ../../Downloads/phpstan.phar/stubs/iterable.stub                                                                             
 ------ ----------------------------------------------------------------------------------------------------------------------------- 
  :271   Method RecursiveArrayIterator::current() overrides method Iterator::current() but is missing the #[\Override] attribute.     
  :276   Method RecursiveArrayIterator::key() overrides method Iterator::key() but is missing the #[\Override] attribute.             
  :282   Method RecursiveArrayIterator::uksort() overrides method ArrayIterator::uksort() but is missing the #[\Override] attribute.  
  :323   Method NoRewindIterator::current() overrides method Iterator::current() but is missing the #[\Override] attribute.           
  :328   Method NoRewindIterator::key() overrides method Iterator::key() but is missing the #[\Override] attribute.                   
  :348   Method LimitIterator::current() overrides method Iterator::current() but is missing the #[\Override] attribute.              
  :353   Method LimitIterator::key() overrides method Iterator::key() but is missing the #[\Override] attribute.                      
  :372   Method InfiniteIterator::current() overrides method Iterator::current() but is missing the #[\Override] attribute.           
  :377   Method InfiniteIterator::key() overrides method Iterator::key() but is missing the #[\Override] attribute.                   
  :407   Method CachingIterator::current() overrides method Iterator::current() but is missing the #[\Override] attribute.            
  :412   Method CachingIterator::key() overrides method Iterator::key() but is missing the #[\Override] attribute.                    
  :444   Method RegexIterator::current() overrides method Iterator::current() but is missing the #[\Override] attribute.              
  :449   Method RegexIterator::key() overrides method Iterator::key() but is missing the #[\Override] attribute.                      
  :459   Method EmptyIterator::current() overrides method Iterator::current() but is missing the #[\Override] attribute.              
  :464   Method EmptyIterator::key() overrides method Iterator::key() but is missing the #[\Override] attribute.                      
 ------ ----------------------------------------------------------------------------------------------------------------------------- 

 ------ ------------------------------------------------------------------------------------------------------------------------------ 
  Line   ../../Downloads/phpstan.phar/stubs/spl.stub                                                                                   
 ------ ------------------------------------------------------------------------------------------------------------------------------ 
  :54    Method SplDoublyLinkedList::offsetGet() overrides method ArrayAccess::offsetGet() but is missing the #[\Override] attribute.  
  :108   Method SplPriorityQueue::current() overrides method Iterator::current() but is missing the #[\Override] attribute.            
 ------ ------------------------------------------------------------------------------------------------------------------------------ 

                                                                                                                        
 [ERROR] Found 58 errors                                                                                                
                                                                                                                        

PHP runtime version: 8.3.12
PHP version for analysis: 8.3.12 (from runtime)

PHPStan version: 1.12.7
PHPStan running from:
<path to home>/Downloads

Extension installer: Not installed

Discovered Composer project roots:
None

Parallel processing scheduler:
# of detected CPU cores:   8
# of analysed files:       1
# of jobs:                 1
# of spawned processes:    1

Elapsed time: 7 seconds
Used memory: 114.55 MB

Machine: A M2 MacBook Pro
Os version: masOS Sequoia 15.0.1
php --version output:

PHP 8.3.12 (cli) (built: Sep 24 2024 18:08:04) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.3.12, Copyright (c) Zend Technologies
    with Xdebug v3.3.2, Copyright (c) 2002-2024, by Derick Rethans
    with Zend OPcache v8.3.12, Copyright (c), by Zend Technologies

Code snippet that reproduces the problem

No response

Expected output

 [OK] No errors

Did PHPStan help you today? Did it make you happy in any way?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions