I have searched and read through many posts here regarding PHP namespaces and accessing class members. I still can't reference the SQLite3 class when wrapped in a custom class and contained within a namepace. Example below:
sqlite3_data_broker.php
namespace DataAccess\SQLiteDb;
class SQLiteBroker {
private $db, $db_pathname;
public function __construct ($dbPathName) {
$this->db_pathname = $dbPathName;
}
public function Open() {
$this->db = new SQLite3($this->db_pathname);
}
public function getPathName() {
return $this->db_pathname;
}
}
some_other_class.php
include('sqlite3_data_broker.php');
$the_db = new \DataAccess\SqliteDb\SQLiteBroker('K:\Path\To\Db\the_data.db');
echo 'Database Full Name: ' . $the_db->getPathName();
$the_db->Open();
Will yield the following:
Database Full Name: K:\Path\To\Db\the_data.db
Fatal error: Class 'DataAccess\SQLite3Db\SQLite3' not found in sqlite3_data_broker.php on line...
Using a namespace I can reference class members but not SQLite3 class wrapped in the open()
function. If I remove the namespace and references to it, that is call the broker class like this: $the_db = new SQLiteBroker('K:\Path\To\Db\the_data.db')
, all works fine.
Is there something I'm missing or not considering in wrapping the SQLite3 class? If it comes down to it I'll remove the namespace, though it would be nice to have it.
PHP Version 5.4.6.