Background
Back in the day when I did C programing we used assume statements to make sure the code was healthy. Something like:
aFunction(int hello)
{
assume(hello < 10);
The cool thing about the assume statement is it was defined to be an empty macro for release compiling and a die on false statement on debug compiling. So the developer had all the benefits of an assert statement checking their assumptions without causing unnecessary bugs or affecting performance in
Problem
Now that I'm working php I'm looking for a similar mechanism. I currently have my assume statement looking something like this:
define(DEBUG, getenv('debug'));
function assume($a)
{
if (DEBUG && !$a)
{
echo 'ASSUME FAILURE <br />';
echo '<pre>';
print_r(debug_backtrace());
die('<pre>');
}
}
assume($a == $b);
As you can see I set the debug flag in the server settings to remove the actual die statement and such. However a function call is still performed and an if statement is still evaluated. This is not a big deal if it only occurs a few thousand times but as the code get's bigger and as these assumes get put into loops this could have a legitimate affect on performance.
Question
Is there a way to tell the interpreter or opcache (I'm currently using zend opcache included in php 5.5) to ignore these assume statements altogether? or is there another method of handling this problem?