How to call functions in other files without including them?

Without using include_once or any include / require, how can I refer to functions declared in other php files in the current directory? Just like we use fopen.

Including the contents of php files containing non-function code can be a mess. It would be better if using a function is automatically associated with its definition.

I also checked How to include () all PHP files from a directory? which requires some code for this.

I can’t find an answer about this anywhere on the Internet, possibly because of too general search queries for this problem.

0
source share
3 answers

glob , :

$phpfiles = glob('mydir/*.php');
foreach($phpfiles as $file)
  do_something_with_the_file($file) // why not include_once $file ?

, , . .

+1

OOP .

, , .

, , - .

+3

OO Processural, , , , .

/.

define( "APP_PATH", dirname( __FILE__ ) ."/" );

function my_autoloader($class)
{
    include 'core/classes/' . $class . '.class.php';
}
spl_autoload_register('my_autoloader');

, :

/ ​​/

.

0

All Articles