Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

autoload functions in php [duplicate]

Tags:

function

php

Is it possible to autoload functions?

What I have is I have written functions distributed over different files named after the function name, so what I need is to autoload the file containing the function automatically. Is there any way to do this?

like image 589
sreejith Avatar asked Feb 26 '23 19:02

sreejith


2 Answers

You can autoload classes, so if you make your functions static methods of classes then it will work.

abstract class Util
{
    static function doSomething() {

    }
}

Usage:

Util::doSomething();
like image 79
Piotr Avatar answered Mar 01 '23 23:03

Piotr


Use:

include("path");

or

require_once("path");

References:

http://php.net/manual/en/function.include.php

http://php.net/manual/en/function.require-once.php

like image 39
Evan Mulawski Avatar answered Mar 01 '23 23:03

Evan Mulawski