PHP函数范围失败

I am struggling to understand scope and what's preventing my new code from working (assuming it is a scope issue).

The following function is in a file PATH.'/includes/custom-functions.php' that references a class:

    function infusion() {
      require_once(PATH.'/classes/infusion.php'); //PATH is defined in WordPress from ~/wp-content/themes/theme/
      return new infusion();
    }

The class is reliant on PATH.'/api/isdk.php' and connection credentials from another file within /api/ directory. From within PATH .'/includes/custom-functions.php', I have many other functions that call $infusion = infusion(); and work perfectly.

PROBLEM
I have created a new file: PATH.'/includes/report.php' which I need to access $infusion = infusion();but can't get to work by either repeating the function infusion() definition from above; using require_once();; or using include();. All 3 of those options simply kill the rest of the code and I can only come to the conclusion - well, I have no conclusion.

Any help would be greatly appreciated.

I'm assuming the code isn't using namespaces, therefore you aren't permitted to redeclare the infusion function (either by redefining the function, or re-including the class).

Your includes/report.php file should simply have:

require_once PATH.'/includes/custom-functions.php';

// your other code here ...

$infusion = infusion();

It may be the case that other files / classes that you're including in your file are already requiring custom-functions.php along the line, so you may be able to skip that entirely. Also note that the PATH constant should have already been defined somewhere (either directly or via an included file) before you attempt to use it. If you set your error_reporting to include E_ALL, you'll get a notification in your error log if that constant doesn't exist.

If that fails, your error log(s) may provide some additional background on what your issue is.