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
2 weeks 5 days ago
2 weeks 6 days ago
2 weeks 6 days ago
2 weeks 6 days ago
2 weeks 6 days ago
2 weeks 6 days ago
2 weeks 6 days ago
3 weeks 2 hours ago
3 weeks 4 hours ago
20 weeks 1 day ago