Possible to send multiple params to callback?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

Possible to send multiple params to callback?

Post by Luke »

I can't seem to find this in the manual. I've never had to send multiple parameters to a callback before, but I'm trying to do essentially this:

Code: Select all

$form->addRule(
    'account_username',
    'Username may only contain alpha-numeric characters',
    'callback',
    array('Zend_Filter', 'isRegex'), array($value, $pattern)
);
so array('Zend_Filter', 'isRegex') would be the callback, and array($value, $pattern) would be the callback params... how would I do this?
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

That really depends on the code using the callback (and the parameters). addRule is a function of what class?
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

Post by Luke »

umm... HTML_QuickForm::addRule()

It doesn't look like it's possible. I don't know what I was thinking, it entirely depends on that library, thanks though. :)
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

But you can pass the array as one parameter to a function that calls another function with the array elements as single parameters

Code: Select all

<?php
function twoParameters($a, $b) {
	echo 'a:', $a, "<br />\nb:", $b;
}

function oneParameter($a) {
	twoParameters($a[0], $a[1]);
}

$value='v'; $pattern='p';
call_user_func('oneParameter', array($value, $pattern));
or with a anonymous trampoline function

Code: Select all

<?php
function twoParameters($a, $b) {
	echo 'a:', $a, "<br />\nb:", $b;
}
$value='v'; $pattern='p';
call_user_func(create_function('$a', 'return call_user_func_array("twoParameters", $a);'), array($value, $pattern));
Post Reply