call function defined in a file include after this file
Suppose I have following files
<?php
include 'file_A';
include 'file_B';
?>
a function defined foo()
in file_B
, is there any way to use it in file_A
by any means???
actually, I am working in a application where a开发者_如何转开发 range of different functions are defined in modules, I want to use these function across the modules without looking where it defined included before or after the file even.
As PHP is an interpreted language, you cannot do this.
What I would do as a solution is extract the methods you need to share into a CommonMethods
class or something similar. Make them static if possible.
Then include the CommonMethods file before file_A
and file_B
.
I'd spend a little time researching design patterns for PHP before continuing your project. Spaghetti code is never a good thing.
精彩评论