Skip to content

(object) array typecast causes rector to alter analysis behavior and fail to load classes #9338

@kkmuffme

Description

@kkmuffme

Bug Report

Subject Details
Rector version last dev-main
Installed as composer dependency

Minimal PHP Code Causing Issue

See https://getrector.com/demo/620f804d-18f8-4fbf-a592-0a7e3a032253

<?php

final class DemoFile
{
	public function run( $args ) {
		if ( ! empty( $args['bar'] ) ) {
			/*$hello = (object) array(
				'a' => 'b',
			);*/
		} else {
			$hello = new Hello( $args );
		}
	}
}

Uncomment the code block to get

<?php

final class DemoFile
{
	public function run( $args ) {
		if ( ! empty( $args['bar'] ) ) {
			$hello = (object) array(
				'a' => 'b',
			);
		} else {
			$hello = new Hello( $args );
		}
	}
}

which results in error:

"Analyze error: "Class Hello was not found while trying to analyse it - discovering symbols is probably not configured properly.". Include your files in "$rectorConfig->autoloadPaths([...]);" or "$rectorConfig->bootstrapFiles([...]);" in "rector.php" config.\nSee https://github.com/rectorphp/rector#configuration",

https://getrector.com/demo/e27f2e9d-9412-40d6-a345-a6be2334496d
(obviously in the online demo I cannot autoloadPaths, but locally I did but still got this error)

Responsible rules

Issue seems to be independent of rules used

This is also the reproducer you requested for

Expected Behavior

  • (object) array typecast should not modify class load behavior
  • (object) array typecast causes classes loaded with autoloadPaths (and probably also bootstrapFiles?) to not be found
  • (object) array typecast should be consistent independent of whether --debug is used or not
  • (object) array typecast should be consistent independent of whether ->disableParallel() is used or not

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions