Jump to content

Recommended Posts

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!

Link to comment
https://forums.phpfreaks.com/topic/185426-php-class-help-icephp/
Share on other sites

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);
}

?>

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();

?>

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();

?>

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?

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.