NuSphere Forums Forum Index
NuSphere Forums
Reply to topic
$server -> register with class method instead of function


Joined: 29 Jun 2006
Posts: 20
Reply with quote
Hi,

is it possible to register a class method instead of a standalone function?
Code:

class myclass
{
   function myfunction()
   {
       // do something
       return true;
   }
}
$class = new myclass()
$server -> register($class -> myfunction);


...something like that.

THanx
View user's profileFind all posts by Doc OlsonSend private message
Site Admin

Joined: 13 Jul 2003
Posts: 7881
Reply with quote
It would required to register both: instance and class method.
No, this is not supported.

_________________
The PHP IDE team
View user's profileFind all posts by dmitriSend private messageVisit poster's website


Joined: 29 Jun 2006
Posts: 20
Reply with quote
ok, so i will wrap the class methods in standalone functions.

thanx
View user's profileFind all posts by Doc OlsonSend private message
Site Admin

Joined: 13 Jul 2003
Posts: 7881
Reply with quote
I'm not sure if it is of any help, but you may try with static methods as they don't require object instance.

_________________
The PHP IDE team
View user's profileFind all posts by dmitriSend private messageVisit poster's website


Joined: 29 Jun 2006
Posts: 20
Reply with quote
no, that's not an option. But that doesn't matter anyway since in the wrapper functions i catch thrown exceptions to convert them to soap faults. The classes used can be used locally too but there an exception handler takes care of the exceptions. After all not a bad thing.
View user's profileFind all posts by Doc OlsonSend private message


Joined: 21 Apr 2008
Posts: 10
Reply with quote
Hi,

You can try following, It has worked for me.

Code:

class myclass
{
   function myfunction()
   {
       // do something
       return true;
   }
}
$server -> register(myclass.myfunction);


After this check you wsdl, you we see all the required things there.

Regards,

Dave Naimish
View user's profileFind all posts by naimish_hitSend private message
Site Admin

Joined: 13 Jul 2003
Posts: 7881
Reply with quote
Quote:
You can try following, It has worked for me

if you have 100 instances of myclass, which one will be called with myfunction? Smile
so it does not look like your suggestion will do.

_________________
The PHP IDE team
View user's profileFind all posts by dmitriSend private messageVisit poster's website


Joined: 18 Oct 2008
Posts: 1
Reply with quote
the original question was:
is it possible to register a class method instead of a standalone function?

Yes it is....do the following:

class ClassName
{
function myfunction()
{
// do something
return true;
}
}
$server -> register(ClassName..myfunction); // Here's the magic...use two periods to separate the className from the function you want to expose.


Side Note:

Although this worked for me I am having a problem getting the function I register to access it's brother and sister functions in the class.

example:
class myclass
{
function myfunction()
{
// do something
return $this->sayHello();
}
function sayHello(){
return 'Hello';
}
}

$server -> register(ClassNameHere..myfunction);

When I try to call the function in soap it returns:
HTTP Error: no data present after HTTP headers

The function call works if I don't reference it's sibling function.
So instead of return $this->sayHello(), I put return 'Hello' and I get a successful reply.
I would imagine this is caused by "Context Confusion". Maybe I'm registering this Class Function wrong. Any advise would be welcome.

Sincerely,
Kokopelli
View user's profileFind all posts by kokopelliSend private message
$server -> register with class method instead of function
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
All times are GMT - 5 Hours  
Page 1 of 1  

  
  
 Reply to topic