Sorry to bother you on the almost perfect patch - but why do you check for $recursive? if it's empty, it will evaluate empty in the line below as well => probably no need to check it