Molerus
Molerus

Reputation: 1

Problem with redeclaring _autoload function when using auto_prepend_file

below this line i´m posting an unsolved question i found on the internet, which is EXACTLY the question i´d like to post:

I run a custom php.ini file so I was able to use auto_prepend_file in the settings, and everything was working just fine until I decided to put an __autoload() function in the prepended file. When I did that PHP shot me an error about redeclaring an already declared function, even though it was only declared once.

Fatal error: Cannot redeclare __autoload() (previously declared in /home/username/php/globalvars.php:37) in /home/username/php/globalvars.php on line 40

Even odder is the fact that it says the next declaration is at the end of the closing brackets of the first declaration, directly after it. I've been normally including this file at the top of each file for a while now, and I thought this could make things easier..apparently not. Any ideas anyone? Thanks in advance.

Upvotes: 0

Views: 1788

Answers (1)

Arnaud Le Blanc
Arnaud Le Blanc

Reputation: 99911

Use spl_autoload_register() instead of declaring __autoload directly.

This allows you to have multiple autoloading functions.

Upvotes: 2

Related Questions