reimplementation of in PHP