2

I would like to use my function, for example DebugR(), but I don't want to use a require or include (with include_path) to load the function file that contains the source.

I know I could use an autoload, but this action must be generic in my php configuration. I think I must create a PHP extension, but is there another way?

1
  • Thank you Jim Puls, i'll remember how edit futurs questions Commented Apr 9, 2009 at 19:09

4 Answers 4

5

There is a PHP configuration line you can do.

The documentation says this :

auto_prepend_file string

Specifies the name of a file that is automatically parsed before the main file. The file is included as if it was called with the require() function, so include_path is used. The special value none disables auto-prepending. 
Sign up to request clarification or add additional context in comments.

Comments

0

Without building the extension, or auto-loading a class of functions or directly requiring the function into the page, or writing the function in the same file, I'm pretty sure there isn't a way without adjusting your PHP configuration.

Out of curiosity, what are the reasons for not wanting to do any of those things?

Comments

0

Why not use an accelerator which caches the code as BC in the memory?
You still need to write the "include" directive.
If extension is where you head, then fork from any of the available open source Accelerators out there.

Comments

0

The only feasible way to do that is to use autoloads like this:

// your_file.php function __autoload($class) { require_once('./classes/' . $class . '.php'); } echo _::Bar(); var_dump(_::DebugR()); echo _::Foo(); // ./classes/_.php class _ { function Bar() { return 'bar'; } function DebugR() { return true; } function Foo() { return 'foo'; } } 

Of course, every function would be stored inside this _ class.

Another alternative, if you are working from within an object is to use the __call() magic method and do something like:

return $this->DebugR(); 

1 Comment

"I know I could use an autoload, but this action must be generic" I don't want to use autoload. Read the voted answer, it's the best response of the problem.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.