<?php
$command = (int)$_GET['command'];
$actions = array(
1 => 'profile',
3 => 'login',
7 => 'show',
9 => 'update',
11 => 'stop',
13 => 'start',
15 => 'remove',
);
//判断命令对应的动作是否存在
if (!array_key_exists($command, $actions)) throw new Exception('404');
$control = new App();
$method = 'on' . ucfirst($actions[$command]);
//判断类里面是否存在该函数
if (!method_exists($control, $method)) throw new Exception('404');
凭感觉猜测题主是需要一个简洁的分发,那么可以考虑
先指出一点错误, 一般检测类似controller这种类方法是否可以被调用, 需要使用is_callable而不是method_exists, 前者检查方法是否可以被调用(存在且公开), 后者只是单纯检查方法是否存在。
看看 Flight 框架 也是另外一种思路