php implementation of functions.py