noahbeach Posted December 17, 2009 Share Posted December 17, 2009 I'm writing a PHP web interface for the open source VOIP server Murmur. Murmur uses the Ice RPC to communicate and Ice has php bindings. I'm getting the common t_variable error, which is usually associated with a misplaced semicolon or bracket, but this doesn't seem to be the case. I can't seem to figure it out and would love a second pair of eyes to see if I'm missing something. The following code throws the error on the "var $base = $ICE->stringToProxy("Meta:tcp -h 127.0.0.1 -p 6502");" line, if that line is commented out it throws the error on the next line: <?php Ice_loadProfile(); class Meta { var $base = $ICE->stringToProxy("Meta:tcp -h 127.0.0.1 -p 6502"); var $meta = $base->ice_checkedCast("::Murmur::Meta"); function getServer($serverid) { return $this->meta->getServer($serverid); } function newServer() { return $this->meta->newServer(); } function getBootedServers() { return $this->meta->getBootedServers(); } function getAllServers() { return $this->meta->getAllServers(); } } $meta = new Meta(); echo $meta->getBootedServers(); ?> The following code works as expected and produces "This works" <?php Ice_loadProfile(); class Meta { var $itWorks = "This works"; function getServer($serverid) { return $this->meta->getServer($serverid); } function newServer() { return $this->meta->newServer(); } function getBootedServers() { return $this->itWorks; } function getAllServers() { return $this->meta->getAllServers(); } } $meta = new Meta(); echo $meta->getBootedServers(); ?> Any help would be awesome! Quote Link to comment https://forums.phpfreaks.com/topic/185426-php-class-help-icephp/ Share on other sites More sharing options...
trq Posted December 17, 2009 Share Posted December 17, 2009 $ICE doesn't seem to be defined anywhere. Quote Link to comment https://forums.phpfreaks.com/topic/185426-php-class-help-icephp/#findComment-978876 Share on other sites More sharing options...
noahbeach Posted December 17, 2009 Author Share Posted December 17, 2009 The Ice_loadprofile() seems to do the job for that. The following is part of the script provided as an example and works fine, returns "Array" since the data type that is returned from the function being echoed is an array. <?php Ice_loadProfile(); try { $base = $ICE->stringToProxy("Meta:tcp -h 127.0.0.1 -p 6502"); $meta = $base->ice_checkedCast("::Murmur::Meta"); //Fetch list of all booted servers, returns an Array echo $meta->getBootedServers(); } catch (Ice_Exception $ex) { print_r($ex); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/185426-php-class-help-icephp/#findComment-978879 Share on other sites More sharing options...
trq Posted December 17, 2009 Share Posted December 17, 2009 Still, its not defined anywhere within your class. Classes have there own scope. Quote Link to comment https://forums.phpfreaks.com/topic/185426-php-class-help-icephp/#findComment-978880 Share on other sites More sharing options...
ngreenwood6 Posted December 17, 2009 Share Posted December 17, 2009 try this: <?php class Meta { var $base; var $meta; function __construct(){ Ice_loadProfile(); $base = $ICE->stringToProxy("Meta:tcp -h 127.0.0.1 -p 6502"); $meta = $base->ice_checkedCast("::Murmur::Meta"); } function getServer($serverid) { return $this->meta->getServer($serverid); } function newServer() { return $this->meta->newServer(); } function getBootedServers() { return $this->meta->getBootedServers(); } function getAllServers() { return $this->meta->getAllServers(); } } $meta = new Meta(); echo $meta->getBootedServers(); ?> Quote Link to comment https://forums.phpfreaks.com/topic/185426-php-class-help-icephp/#findComment-978882 Share on other sites More sharing options...
noahbeach Posted December 17, 2009 Author Share Posted December 17, 2009 Closer! I was typing in that code when I checked and saw you had the same idea. With my code revised to match the suggested, I got the new error: Fatal error: Call to a member function stringToProxy() on a non-object in /var/www/test.php on line 20 I then added global $ICE; To the __construct function and now receive a similar error on my getBootedServers function: Fatal error: Call to a member function getBootedServers() on a non-object in /var/www/test.php on line 39 Current code: <?php class Meta { var $base; var $meta; function __construct() { Ice_loadProfile(); global $ICE; $base = $ICE->stringToProxy("Meta:tcp -h 127.0.0.1 -p 6502"); $meta = $base->ice_checkedCast("::Murmur::Meta"); } // Returns an interface to the specific server function getServer($serverid) { return $this->meta->getServer($serverid); } function newServer() { return $this->meta->newServer(); } function getBootedServers() { return $this->meta->getBootedServers(); } function getAllServers() { return $this->meta->getAllServers(); } } $meta = new Meta(); echo $meta->getBootedServers(); ?> Quote Link to comment https://forums.phpfreaks.com/topic/185426-php-class-help-icephp/#findComment-978891 Share on other sites More sharing options...
ngreenwood6 Posted December 17, 2009 Share Posted December 17, 2009 try commenting out the line under your Meta classes getBootedServers function or better just set it to return test or something. I think the problem is with how you are trying to call that function. Quote Link to comment https://forums.phpfreaks.com/topic/185426-php-class-help-icephp/#findComment-978898 Share on other sites More sharing options...
noahbeach Posted December 17, 2009 Author Share Posted December 17, 2009 Yeah that resolves that error, but then again thats because that function no longer does anything. But we know that you are correct in your assumption that I seem to be calling it wrong. Basically all I'm trying to do with this class is create a wrapper class for the Ice Murmur::Meta class. The Murmur::Meta class has a function called getBootedServers() that fetches a list of all currently running servers, its return value list (array) of interfaces for running servers. A working (without my wrapper class) example of calling this function is: <?php Ice_loadProfile(); try { $base = $ICE->stringToProxy("Meta:tcp -h 127.0.0.1 -p 6502"); $meta = $base->ice_checkedCast("::Murmur::Meta"); //Fetch list of all booted servers, returns an Array echo $meta->getBootedServers(); } catch (Ice_Exception $ex) { print_r($ex); } ?> The $base = line creates a proxy to the Meta object, then the $meta = line narrows the proxy to the proper type. If the above works, I don't see where I'm calling it different from within my class? Quote Link to comment https://forums.phpfreaks.com/topic/185426-php-class-help-icephp/#findComment-978908 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.