1

How to check call_user_func_array return data PHP:

i have class 1:

class MyClass
{
   public function show()
   {
      echo 'This is show function';
   }
}

class 2:

class MyClass2
{
   public function show2()
   {
      return 'This is show2 function';
   }
}

now, i check:

if(isset(call_user_func_array(array(new MyClass,'show'),$params)))
{
   echo 'Has return data';
}
else
{
   call_user_func_array(array(new MyClass,'show'),$params);//run normal function
}

if(isset(call_user_func_array(array(new MyClass2,'show2'),$params)))
{
   echo 'Has return data';
}
else
{
   call_user_func_array(array(new MyClass2,'show2'),$params);//run normal function
}

but not working, somebody can help me?

5
  • What are you trying to check? Are you looking for method_exists() instead? Commented Mar 1, 2014 at 3:36
  • I want to check if the function can return, I will not call call_user_func_array, if there is no return, then I will echo the call to call_user_func_array text as in the example. Commented Mar 1, 2014 at 3:41
  • You want to know if the function returns a value? What kind of values do you want to check for? Boolean? String? Null? Array? Commented Mar 1, 2014 at 3:43
  • What is not working? Do you get an error? Does it echo the wrong thing? And you're calling the function twice. If it echos, it will echo twice... Commented Mar 1, 2014 at 3:44
  • Don't use isset() for these checks. You just want to verify that a value is returned, not that a variable is set. Commented Mar 1, 2014 at 3:48

1 Answer 1

0

Warning isset() only works with variables as passing anything else will result in a parse error. For checking if constants are set use the defined() function.

http://www.php.net/manual/en/function.isset.php

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.