Skip to content

Fails to Process Files with Dynamic Class Instantiation and Direct String Parameters #1108

Closed
@oskarmodig

Description

@oskarmodig

Bug report

Question Answer
PHP-Scoper version 0.18.16
PHP version 8.2.14
Platform with version Windows 11, running command in WSL, Ubuntu 22.04.3 LTS

php-scoper seems to silently skip files containing dynamic class instantiation when a direct string value is passed as a parameter to the class constructor. The issue occurs when a string literal is passed directly, but the problem does not occur when the string is stored in a variable or within an array. This behavior is inconsistent and leads to skipped files in certain scenarios.

Tested files

Test File 1 (Works):

<?php
namespace Online_Shared\Modules;
$ajax_syncer = new $syncer_class();

Test File 2 (Fails):

<?php
namespace Online_Shared\Modules;
$ajax_syncer = new $syncer_class( 'test' );

Test File 3 (Works - String in Variable):

<?php
namespace Online_Shared\Modules;
$test = 'test';
$ajax_syncer = new $syncer_class( $test );

Test File 4 (Works - String in Array):

<?php
namespace Online_Shared\Modules;
$ajax_syncer = new $syncer_class( array( 'test' ) );

Expected Behavior

  • All four test files should be scoped successfully, prepending the prefix to the namespace in the examples

Actual Behavior

  • Test File 1, Test File 3, and Test File 4 are processed as expected.
  • Test File 2 is entirely skipped during the scoping process, and is added to the output folder unchanged. All other files in the project are scoped properly.
scoper.inc.php
<?php
return array(
   'prefix'            => 'Online_Shared_Sync',
   'php-version'       => '8.2',
   'output-dir'        => 'online-shared',
   'finders'           => array(
   	\Isolated\Symfony\Component\Finder\Finder::create()
   	                                         ->files()
   	                                         ->in( 'vendor/oskarmodig/online-shared' )
   	                                         ->name( '*.php' ),
   ),
);
Output
$ rm -rf online-shared
$ php vendor/humbug/php-scoper/bin/php-scoper add-prefix
>     ____  __  ______     _____
>    / __ \/ / / / __ \   / ___/_________  ____  ___  _____
>   / /_/ / /_/ / /_/ /   \__ \/ ___/ __ \/ __ \/ _ \/ ___/
>  / ____/ __  / ____/   ___/ / /__/ /_/ / /_/ /  __/ /
> /_/   /_/ /_/_/       /____/\___/\____/ .___/\___/_/
>                                      /_/
> 
> PhpScoper version 0.18.16@aff0ef9
> 
>  122/122 [▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓] 100%
> 
>                                                                                                                         
>  [OK] Successfully prefixed 122 files.                                                                                  
>                                                                                                                         
> 
>  // Memory usage: 16.25MB (peak: 20.13MB), time: 7.91s

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions