1

Here it what I want to do: I have an object

class TestObject {
      public function __call($name,$args){
        if($name == 'somemethod'){
          print "Yesssss!!!!!!";
        }
      }
}

than in code i'm calling this method like this:

$obj = new TestObject()
$obj->somemethod()  // should work according to http://www.php.net/manual/en/language.oop5.overloading.php#object.call
call_user_func(array('myobject','somemethod')) // this does not work!!!

Is there any way to get the last example to work?

1
  • Have you tried array($obj, 'somemethod');? Commented Feb 17, 2013 at 16:26

2 Answers 2

0

You can use

call_user_func(array($obj,'somemethod'));

or

$method = 'somemethod';
$obj->$method();
Sign up to request clarification or add additional context in comments.

4 Comments

call_user_func(array($obj,'somemethod')); - this wont call unexistent method
It does call the '__call' method if it doesn't exist.
$obj->$method(); - the problem is that I cannot use this type of calling. i need to use call_user_func
Hmm, yes it does call __call method in test script.
0
$obj_name = 'myobject';
$method_name = 'somemethod';
${$obj_name}->${$method->name()};

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.