Converting Java code to PHP