converted from java to php