Log in

View Full Version : defining functions inside datamanagers


merk
11-19-2005, 02:13 AM
I have tried to define a new function inside the attachment datamanager


if(!function_exists('verify_fieldname'))
{
function verify_fieldname(&$data)
{
/*<do stuff>*/
}
}

$this->validfields['fieldname'] = array(TYPE_HERE, REQ_NO, VF_METHOD);

A fatal error occurs stating the method cannot be found.

Am i doing something wrong? this is how it is described in the vBulletin manual.

Andreas
11-19-2005, 02:46 AM
Can you give the exact location where this is stated in the manual?
As it seems to be wrong ;)

You cannot create methods for objects at runtime; this is a PHP limitation.

What you can do is using a lamda function that calls your custom verification function:


if (!function_exists('verify_fieldname'))
{
function verify_fieldname(&$dm, &$data)
{
/*<do stuff>*/
}
}


$this->validfields['fieldname'] = array(TYPE_HERE, REQ_NO, 'return verify_fieldname($data, $dm);');

merk
11-19-2005, 03:16 AM
Sorry, my mistake, the code in the manual shows what you've pasted, i was trying to use VF_METHOD where it should have been just a string.

Got it working now, thanks :)