昊漫玉 发表于 2017-3-27 10:13:37

PHP 的一些不太常用的特性

1. 变量函数名,可以用字符串拼接函数名



function aa($str) {
  echo $str;
}
$function = "aa";
$function('Hello');
// OR
call_user_func($function, $param);
2. 列出所有函数,判断某个函数是否存在

get_defined_functions()
function_exist()
3. 接受 PUT 请求,PHP REST 必备

parse_str(file_get_contents('php://input'), $put_vars);
4. 从字符串解析时间

echo date('Y-m-d', strtotime('-1 month ago'));
5. DEBUG 查看调用 backtrace


$backtrace = debug_backtrace();
var_export($backtrace[0])
die();
6. 交互式命令行,命令行执行 PHP
php -a 和 php -r ‘echo “hello”;’
更多请看 php -h
7. 内存使用检测

memory_get_peak_usage()
memory_get_usage()
页: [1]
查看完整版本: PHP 的一些不太常用的特性