Filters derived from PHP classes

A less well-known coding technique makes it possible to also execute a PHP class method. When requested to process a filter written as “x::y”, SPIP will look for a “filter_x” PHP class with an executable “y” method. If it doesn’t find one, it will then look for a class “filtre_x_dist”, and then finally for a class “x”.



Let’s imagine a PHP class which has been defined as shown below. It contains a (recursive) function which calculates factorials (x! = x*(x-1)*(x-2)*...*3*2*1).

class Math{
  function factorial($n){
    if ($n==0) 
      return 1;
      return $n * Math::factorial($n-1);

This new function could be called within SPIP as follows:

// returns 362880

Author Mark Baber Published : Updated : 12/03/23

Translations : English, français, Nederlands