1. return isset($cache[$cls]) ? $cache[$cls] : $cache[$cls] = new $cls; 2. return @$cache[$cls] ?: $cache[$cls] = new $cls;
我读了某个地方@需要大量时间执行(我不知道为什么),特别是当警告/通知实际上被发出和被禁止的时候. isset()另一方面意味着额外的哈希查找.那么哪个更好,为什么?
我确实希望在开发和生产服务器上保持全球的E_NOTICE.
根据这篇文章10 Performance Tips to Speed Up PHP,警告需要额外的执行时间,并声称@运算符是“昂贵的”.
Cleaning up warnings and errors beforehand can also keep you from
using @ error suppression,which is expensive.
http://www.php.net/manual/en/language.operators.errorcontrol.php
If you have set a custom error handler function with
set_error_handler() then it will still get called,but this custom
error handler can (and should) call error_reporting() which will
return 0 when the call that triggered the error was preceded by an @.If the track_errors feature is enabled,any error message generated by the expression will be saved in the variable $PHP_errormsg. This variable will be overwritten on each error,so check early if you want to use it.