I'm experiencing an odd problem with Pear DB where a global variable gets "lost" in classes and functions.
I'm creating the
$db = DB::connect(DSN);
object, which is then useable just fine throughout the script, but as soon as I create a function or class and use
global $db;
in them, then the $db object somewhat changes.
A var_dump($db) matches exactly in both, the script and the function/class, with the exception that the $db is not useable in the later ones.
Resulting in "call to undefined function" errors and the like.
Only by removing the global scope and by adding another
$db = DB::connect(DSN);
to the function/class, I can start using the $db object again.
However, this is not an acceptable solution, since it would mean that each call to a function or class would require to open a new MySQL connection, instead of using the same one throughout the scripts lifetime.
To add to the confusion:
the problem does not exist on my local windows machine, but only happens on my linux server.
PHP versions match, same with the MySQL and Pear DB versions.
I even downgraded php to 4.3.10, due to the recent reference changes in 4.4.0, but the same error still occurs.
This is rather puzzling, since the variable gets passed just fine, yet still seems to have been modified somehow, due to all the warnings, notices and errors when trying to use the global $db object within a function or class.
Does anyone have an idea what might be causing this problem?