For example, if I implement some simple object caching, which method is faster?
1. return isset($cache[$cls]) ? $cache[$cls] : $cache[$cls] = new $cls;
2. return @$cache[$cls] ?: $cache[$cls] = new $cls;
I read somewhere @
takes significant time to execute (and I wonder why), especially when warnings/notices are actually being issued and suppressed. isset()
on the other hand means an extra hash lookup. So which is better and why?
I do want to keep E_NOTICE on globally, both on dev and production servers.
$cls
is not a string/integer? :) – Upireturn !empty($cache[$cls]) ? $cache[$cls] : $cache[$cls] = new $cls;
– Heartwoodnew $cls
if that's what you mean. – Tuberculinfalse
,""
or0
will result in overriding the cache each time it's called. I recommend reading the type comparison table. – Heartwood@
is being improved with each new PHP version, but that's all I know. The rest is coding style I'd say, this was never a performance issue first-hand. It's how you deal with errors and warnings. – Hardunn