How to include only functions from php file?

Possible duplicate:
Including PHP functions from another file

I am creating code that uses function calls that exist in a third party php file. This 3p php file is not a function library, but also contains embedded code.

How do I call functions without executing inline code?

edit: duplicate of Including PHP functions from another file ?

+4
source share
5 answers

How do I call functions without executing inline code?

You can not.

You may be able to disable include output using output buffering , but the code will still execute.

I don’t think there is a good way to do this without making copies of the corresponding inclusions and removing the embedded code from them.

+5
source

The simple answer is: you cannot. An include call is simply opening a file and running eval() in the content.

0
source

How to split the source file into a function file and its own code file and include them? That way, the source file will work as before, and you can only include functions in the script.

0
source

Theoretically, this is possible with evading the filtered contents of the file, but filtering code is not an easy task in terms of scripts and performance.

0
source

If all your functions are defined at the top of the file you want to include, you can add such a structure to it immediately after the function definitions:

 if (something that would be true if the file was included) { return; } 

For example, if the script executing include already defined a variable called $myVar , you can do:

 if (isset($myVar)) return; 

This will cause the included file to stop executing and return control to your original script.

However, the best solution is to create another file, for example, for example. 'functions.php' and include('functions.php'); in both scripts ...

0
source

All Articles