api - PHP Function Scope Failure -
i struggling understand scope , what's preventing new code working (assuming scope issue).
the following function in file path.'/includes/custom-functions.php' references class:
function infusion() { require_once(path.'/classes/infusion.php'); //path defined in wordpress ~/wp-content/themes/theme/ return new infusion(); } the class reliant on path.'/api/isdk.php' , connection credentials file within /api/ directory. within path .'/includes/custom-functions.php', have many other functions call $infusion = infusion(); , work perfectly.
problem
have created new file: path.'/includes/report.php' need access $infusion = infusion();but can't work either repeating function infusion() definition above; using require_once();; or using include();. 3 of options kill rest of code , can come conclusion - well, have no conclusion.
any appreciated.
i'm assuming code isn't using namespaces, therefore aren't permitted redeclare infusion function (either redefining function, or re-including class).
your includes/report.php file should have:
require_once path.'/includes/custom-functions.php'; // other code here ... $infusion = infusion(); it may case other files / classes you're including in file requiring custom-functions.php along line, may able skip entirely. note path constant should have been defined somewhere (either directly or via included file) before attempt use it. if set error_reporting include e_all, you'll notification in error log if constant doesn't exist.
if fails, error log(s) may provide additional background on issue is.
Comments
Post a Comment