How to use a static class method as a filter for Kohana's Validation Library?

Kohana's Validation library has a pre_filter() method which lets you apply any PHP function to fields to be validated, as trim(), etc. I tried to use a static method as a filter, but won't work: $validation->pre_filter( 'field_name', 'class::method' )

What that does is create two filters, one with class and antoher one with method.

Any clues?


A callback is one of PHP's pseudo-types. It will let you pass a

  1. function
  2. method of an instantiated object
  3. static method/class method

to a PHP function/method that's expecting a callback, and the PHP function/method will know what to do with it.

From the manual

A PHP function is passed by its name as a string. Any built-in or user-defined function can be used, except language constructs such as: array(), echo(), empty(), eval(), exit(), isset(), list(), print() or unset().

A method of an instantiated object is passed as an array containing an object at index 0 and the method name at index 1.

Static class methods can also be passed without instantiating an object of that class by passing the class name instead of an object at index 0.

So, to use a static method in place of a callback string, you'd use


If Kohana is using standard PHP callbacks, this should give you what you want.

To use a static method call back the callback needs to be an array.. for example:

array('MyCoolClassName', 'methodName');

so assuming its using call_user_func then your method call should be:

$validation->pre_filter( 'field_name', array('MyCoolClassName', 'methodName'));

or if you need to use an object instance:

$validation->pre_filter( 'field_name', array($objectInstance, 'methodName'));

Need Your Help

Why do I need to use document.write instead of DOM manipulation methods?

javascript ads document.write

I'm trying a new ad service, and as far as I know they don't provide a functional interface to loading their ads. We want to display different ad sizes depending on the user's screen size, and this

Windows - VBScript - Determine IP address of computer on network

scripting vbscript windows-xp ip-address

I have written some VBScripts to automate tasks that I perform on computers over the network. These work great for most tasks however within our network we have problems with the IP address in DNS...