Variable type is null in remote class
Here is my main class
class pMr {
const VERSION = '0.0.3';
public $_connection;
private $_sessionName = 'LoginSession';
public function __construct($function = null) {
...
$this->buildConnection('Predis');
...
}
private function buildConnection($type = 'Predis') {
...
if($type == 'Redis') {
...
} else if($type == 'Predis') {
try {
$this->_connection = new Predis\Client(array(
'host' => $_SESSION[$this->_sessionName]['hostname'],
'password' => $_SESSION[$this->_sessionName]['password'],
'database' => $_SESSION[$this->_sessionName]['database'],
));
} catch (ClientException $e) {
die($e->getMessage());
}
var_dump(gettype($this->_connection));
}
}
}
}
Now, when that code runs, I get string(6) "object"
, which is expected. Now, here is another class, which is loaded inside the main class and then executed (a function is called).
class Interface {
static $_execOnLoad = true;
public static function getRedisVersion() {
global $pMr;
var_dump(gettype($pMr->_connection));
}
}
Now, in that function (when its called), returns NULL. This is the same variable that returns as an object in the above code. Why is this, and what is the work ar开发者_开发问答ound?
Perform var_dump($pMr);
for both objects and see its object#. I bet you just have different objects.
精彩评论