Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:48163 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 80636 invoked from network); 29 Apr 2010 18:30:25 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 29 Apr 2010 18:30:25 -0000 Received: from [127.0.0.1] ([127.0.0.1:14562]) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ECSTREAM id 41/D2-64641-140D9DB4 for ; Thu, 29 Apr 2010 14:30:25 -0400 X-Host-Fingerprint: 84.152.247.183 p5498F7B7.dip.t-dialin.net Received: from [84.152.247.183] ([84.152.247.183:7671] helo=localhost.localdomain) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 50/A2-64641-62BC9DB4 for ; Thu, 29 Apr 2010 14:08:39 -0400 Message-ID: <50.A2.64641.62BC9DB4@pb1.pair.com> To: internals@lists.php.net Date: Thu, 29 Apr 2010 20:08:39 +0200 User-Agent: Thunderbird 2.0.0.23 (Windows/20090812) MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-15; format=flowed Content-Transfer-Encoding: 7bit X-Posted-By: 84.152.247.183 Subject: IF clause with precondition From: soenke.brecht@web.de (=?ISO-8859-15?Q?S=F6nke_Brecht?=) Following code snippet did raise warnings concerning missing single array values ($buffer[$SourceColumnNo] is NULL for some keys) if(is_numeric($SourceColumnNo = array_search($ColumnName, $SourceColumns[$SourceFileName]))) { /* * The table column name was found in the current source file * now store it with the column order number of the table at the correct * position of the ValueArray which will later be transferred to the * table. Sometimes the decimal seperator is given as comma "," instead * of point "." this is adjusted as well. */ $ValueArray[$ColumnNo] = str_replace(",", ".", trim($buffer[$SourceColumnNo])); } My solution was to wrap around if(isset($buffer[$SourceColumnNo])){...} Is there a way to get this additional if condition into the code snippet without evaluating the warning raising second part? Putting both conditions into the clause still causes both conditions to be evaluated, regardles if the full clause maybe never true because FALSE AND sth. will always be FALSE. if(isset($buffer[$SourceColumnNo]) AND is_numeric($SourceColumnNo = array_search($ColumnName, $SourceColumns[$SourceFileName]))){...}; Is for instance this evaluation behaviour controllable? Error suppression with @ is not acceptable and try / catch with error to exception conversion is as well causing code overhead and reduces readability. As third option is to use ternary operator: if(isset($buffer[$SourceColumnNo]) ? (is_numeric($SourceColumnNo = array_search($ColumnName, $SourceColumns[$SourceFileName]))) : FALSE){}; Is this real good practise? Is this code still readable and does it still meet common maintainability requirements? Thanks for your help.