Skip to content

Iterating over empty variable #9277

@ondrejmirtes

Description

@ondrejmirtes

Just a heads-up: The latest dev version of PHPStan (soon to be released as 0.12.49) found a bug in InitCommand.php:

 ------ ------------------------------------------------------ 
  Line   src/Composer/Command/InitCommand.php                  
 ------ ------------------------------------------------------ 
  460    Empty array passed to foreach.                        
  463    Call to function unset() contains undefined variable  
         $requiredPackage.                                     
 ------ ------------------------------------------------------ 

The code in question:

foreach ($requires as $requiredPackage) {
$existingPackages[] = substr($requiredPackage, 0, strpos($requiredPackage, ' '));
}
unset($composer, $installedRepo, $requiredPackage);

The truthy $requires is eliminated a few lines above in if ($requires) that ends with return $result.

The foreach on line 460 can probably just be deleted, or maybe it's meant to mean something else and needs to be modified :)

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