Assignment has the lowest operating precedent doesnt it? [bar crap stuff like commas]
So surely the !$myBuff should fire off before the = apc_fetch() ?
if (!$myBuff = apc_fetch('theStoreBufferName'))
Should execute as:
if ((!$myBuff) = apc_fetch())
Ergo it wouldnt execute as you think it would??
You may be correct... depends on when the ! is evaluated in relation to the assignment - but if you walk through the evaluation of that statement, it's either going to evaluate on whether the $myBuff has anything OR the apc_fetch - and in either case, the result would be what I am looking for. To make it absolutely explicit it should prolly be written like this:
if (!($myBuff = apc_fetch())) { ...
to force the evaluation of the whole thing... but it works perfectly in both cases because the whether the NOT is applied against myBuff or apc_fetch (which it would be in your question) the net result of the IF is the same.
Excellent question though.
Also re the efficiency of the statement.
Isnt the only thing being omitted is a test [to check if $myBuff contains anything or not?]
So if you were to write it out fully itd be
$myBuff = apc_fetch();
if (!$myBuf) { .... }
Absolutely. In fact I write interchangeably that way. The only diff is another line of code. I read an article a long time ago that the way the PHP opcodes work, if you can limit line calls you are more efficient - ergo the reason for the horrific lines in the SMF code base that look like this:
echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"', $context['right_to_left'] ? ' dir="rtl"' : '', '><head>
<meta http-equiv="Content-Type" content="text/html; charset=', $context['character_set'], '" />
<meta name="description" content="', $context['page_title'], '" />', empty($context['robot_no_index']) ? '' : '
<meta name="robots" content="noindex" />', '
<meta name="keywords" content="PHP, MySQL, bulletin, board, free, open, source, smf, simple, machines, forum" />
<script language="JavaScript" type="text/javascript" src="', $settings['default_theme_url'], '/script.js?fin11"></script>
<script language="JavaScript" type="text/javascript"><!-- // --><![CDATA[
var smf_theme_url = "', $settings['theme_url'], '";
var smf_images_url = "', $settings['images_url'], '";
var smf_scripturl = "', $scripturl, '";
var smf_iso_case_folding = ', $context['server']['iso_case_folding'] ? 'true' : 'false', ';
var smf_charset = "', $context['character_set'], '";
// ]]></script>
<title>', $context['page_title'], '</title>';
... where they're using the comma in an echo statement to keep lots of output contained in one line. NEt-net it really doesn't make that much difference in a small app, but in a larger one with lots of processing before a page is delivered it may very well make a difference. Note the embedded immediate-ifs in that line as well... just horrible to read.
Really, great qqs. Hope my answers rose to the task!
/p