shuja
shuja

Reputation: 79

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.

Upvotes: 0

Views: 303

Answers (1)

Chuck Callebs
Chuck Callebs

Reputation: 16441

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.

Upvotes: 2

Related Questions