Generic functor in PHP