In my code I have a file that initializes a MySQLi class.
File a:
$db = new Database(); //MySQLi class
Anyways, there is a file that includes this database class. That file also includes other files that has function declared in it. I'm using global to contact $db
File b:
function xy(){
global $db;
$sql = "..."
return $db->getArray($sql);
}
Testfile:
require "file_a.php";
require "file_b.php";
require_once "PHPUnit/Framework/TestCase.php";
class testProblemStatistics extends PHPUnit_Framework_TestCase {
testArray(){
$this->assertTrue(array_key_exists('xy', $this->xy())
}
}
I get:
Fatal error: Call to a member function getArray() on a non-object
I investigated:
var_dump($db);
function xy(){
global $db;
var_dump($db);
...
}
The first dump gave me the MySQLi object,
the second dump gave me NULL
Something is wrong with the global variable in file_b.
Additional Information: I'm using PHPUnit and I'm running it in the command prompt. In a normal browser everything works fine.