Also both function are not the same! Look at the detail. The JS version does NOT return, but the PHP does. That is why the after is never called.