Extended and fixed PHP example