PHP Classes

Method support to set_modification(), set_onsuccess()

Recommend this page to a friend!

      Auto form  >  All threads  >  Method support to...  >  (Un) Subscribe thread alerts  
Subject:Method support to...
Summary:Passing a external class method instead of a function
Messages:3
Author:Diego Medeiros
Date:2014-07-13 18:14:03
Update:2014-07-14 02:12:40
 

  1. Method support to...   Reply   Report abuse  
Picture of Diego Medeiros Diego Medeiros - 2014-07-13 18:14:03
Hello! I'm trying to pass a class method to parameter of "set_modification", "add_custom_validation" and "add_custom_validation" without success:

$form->set_modification ($OtherClass->my_function());
$form->add_custom_validation ($OtherClass->my_function(), "Lorem ipsum");
$form->set_onsuccess ($OtherClass->my_function());

When you try this, the method is executed before the right time.

Thus it is always necessary to place the function outside the scope of my classes ....

Is there any way around this?

  2. Re: Method support to...   Reply   Report abuse  
Picture of Arturs Sosins Arturs Sosins - 2014-07-13 20:16:00 - In reply to message 1 from Diego Medeiros
The way you do it, it will execute the method and will try to set the result as callback function

Internally for callbacks class uses call_user_func function:
php.net/manual/en/function.call-use ...

which means to call method of some class, you would need to pass it as array:
$form->set_modification (array($OtherClass, 'my_function'));

Only note that method should be public ;)

  3. Re: Method support to...   Reply   Report abuse  
Picture of Diego Medeiros Diego Medeiros - 2014-07-14 02:12:40 - In reply to message 2 from Arturs Sosins
Thanks for much! You saved my day! :)

 
For more information send a message to info at phpclasses dot org.