PHP的优化之道

最后更新于:2022-04-02 02:19:23

[TOC] ### 静态化属性 因为静态化后,执行过程中只初始化一次 ``` function send_http_status($code) { static $_status = array( // Informational 1xx 100 => 'Continue', 101 => 'Switching Protocols', // Success 2xx 200 => 'OK', 201 => 'Created', 202 => 'Accepted', 203 => 'Non-Authoritative Information', ... ... ); } ``` ### 递增一个未预定义的局部变量要比递增一个预定义的局部变量慢9至10倍 ### 检测字符串长度 ``` if (strlen($foo) < 5) { echo "Foo is too short"; } if (!isset($foo{5})) { echo "Foo is too short"; } //更优 ```
';