Last week, Matt Farina tossed me a question about the best approach to introspecting code in PHP, particularly in relation to whether or not the situation was a good candidate for using PHP's Reflection API. The original (now outdated) patch he gave me as an example had the following block of code in it:
<?php
$interfaces = class_implements($class);
if (isset($interfaces['JSPreprocessingInterface'])) {
$instance = new $class;
}
else {
throw new Exception(t('Class %class does not implement interface %interface', array('%class' => $class, '%interface' => 'JSPreprocessingInterface')));
}
?>
I've used Reflection happily in the past. I've even advocated for it in situations where I later realized it was the totally wrong tool for the job. But more importantly, I'd accepted as 'common knowledge' that Reflection was slow. Dog-slow, even. But Matt's question was specific enough that it got me wondering just how big the gap ACTUALLY was between the code he'd shown me, and the Reflection-based equivalent. The results surprised me. To the point where I ended up writing a PHP microbenching framework, and digging in quite a bit deeper.
Recent comments
3 min 35 sec ago
2 hours 34 min ago
16 hours 55 min ago
16 hours 56 min ago
16 hours 56 min ago
17 hours 50 sec ago
17 hours 2 min ago
17 hours 6 min ago
17 hours 19 min ago
17 hours 29 min ago