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”.
[(#TAG|class::method)]
Example
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;
else
return $n * Math::factorial($n-1);
}
}
This new function could be called within SPIP as follows:
[(#VAL{9}|Math::factorial)]
// returns 362880