Maintenance of the company's previous project, the staff who wrote the project has left, now I need to maintain, but now the project uses a lot of'goto', I want to know how to read it. How to sort after removing'goto'statements, making it easier for people to understand. For short, I want to format the messy code in the left side to be like the right side in the picture
//**this code
defined('IN_IA') or exit('Access Denied');
class Md_daojiaModuleSite extends WeModuleSite
{
public function doPageUploadmap3()
{
goto A25dm;
ADcuT:
ZLMND:
goto wJ44l;
z_M2Z:
if (empty($_FILES["file"]["tmp_name"])) {
goto ZLMND;
}
goto RnW8Z;
M61ng:
$tempfile = ATTACHMENT_ROOT . "/audios/" . $name;
goto ReGaV;
A25dm:
global $_GPC, $_W;
goto z_M2Z;
RnW8Z:
$exname = strtolower(substr($_FILES["file"]["name"], strrpos($_FILES["file"]["name"], ".") + 1));
goto BO3TT;
wJ44l:
return $this->result(0, '', "attachment/audios/" . $name);
goto Qx8PP;
BO3TT:
$name = md5(time()) . "." . $exname;
goto M61ng;
ReGaV:
move_uploaded_file($_FILES["file"]["tmp_name"], $tempfile);
goto ADcuT;
Qx8PP:
}
}
You basically just reproduce what the interpreter would do:
From top to bottom, look at each
goto
statement.Shuffle the according jump marker and code section directly behind it.
So you end up with:
Once you have associated each
marker:
right behind thegoto
, just remove or comment those out.