<?php
function compose($f, $g) {
    return function() use($f, $g) { return $f(call_user_func_array($g, func_get_args())); };
}

$f = function($x) { return $x + 1; };
$g = function($l) { return count($l); };

echo compose($f, $g)([1,2,3]);