Skip to content

Reflection error: [class] not found #5276

@sedimentation-fault

Description

@sedimentation-fault

Dear phpstan support,

this is actually not a bug - it should be a discussion instead. But I was not able to start a discussion, because my browser is not one of the four supported browsers in Github (Chrome, Chrome, Chrome, or...Chrome. :roll:) and I refuse to change browser for Github's sake. Feel free to move it to discussions.

My problem to discuss is this:

I have an "old-fashioned" PHP project, with lots of class constants (and file constants, and language constants...). Its code starts like this:

include_once("configuration.inc.php");
include_once(CLASS_XXX);
include_once(CLASS_YYY);

Now, phpstan needs of course to know where to get all this from. So I pass it (with -a yyy.php) a file yyy.php where CLASS_XXX and CLASS_YYY are defined as follows:

   define("SITE_PATH","/some/full/path/to/site/dir");
   define("FILE_SEPARATOR", "/");
   define("APPL_PATH",SITE_PATH.FILE_SEPARATOR."appl");
   define("CONFIG_FILE",APP_PATH.FILE_SEPARATOR."mydefs.inc.php");
   include_once(CONFIG_FILE);

You don't see CLASS_XXX etc. being defined here? Right, they are defined in the included CONFIG_FILE, or in the files that this CONFIG_FILE includes itself.

When I read about the -a option and the fact that the file passed there is "executed" by PHP, I thought it would also execute the

include_once(CONFIG_FILE);

statements, thus including CONFIG_FILE (whose name is known at that point) and all files it includes itself. But this does not seem to be the case, as phpstan complains that it cannot find the class zzz in the first class

class myClass extends zzz {...

What can I do about it? Any suggestions? Do I have to inspect all include's and write an autoloader script? Is there some tool that can do this for me (read a file and all its include's recursively, then write the autoloader.php for me)? Or, maybe, I miss some option in phpstan that does exactly this?

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