Re: [PHP] Broken IF behavior? (Changing the branch changes the evaluation)

2009-07-29 Thread Peter Ford
Matt Neimeyer wrote:
 It's exactly what I would expect... The content of the row... But in
 any case, what does changing the content of the { } branch have to do
 with how the IF() itself is evaluated?
 
 array(4) {
   [0]=
   string(8) CustName
   [config]=
   string(8) CustName
   [1]=
   string(11) Sample Cust
   [value]=
   string(11) Sample Cust
 }
 
 

The if() *is* being evaluated *the same* whatever the content of that branch,
but when there's no content, you see no result...

It always looks odd to me to have empty if branches - why do you not just write

if ($Ret) { return $Ret; }

Anyway, the !$Ret branch is being executed because the fetch operation will
return NULL (or FALSE or something equivalent) when there are no results.



-- 
Peter Ford  phone: 01580 89
Developer   fax:   01580 893399
Justcroft International Ltd., Staplehurst, Kent

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Broken IF behavior? (Changing the branch changes the evaluation)

2009-07-28 Thread Eddie Drapkin
On Tue, Jul 28, 2009 at 2:48 PM, Matt Neimeyerm...@neimeyer.org wrote:
 Background: I'm converting a webapp from Visual FoxPro as a backend to
 MySQL... However one part of our app (a system status checker) is
 common code between the versions.

 I've got the following function... In English (in case it's not
 apparent), if the version of the app is 2.0 or higher, then use MySQL
 functions, otherwise use the ODBTP function to connect to VFP.

 function my_fetch_array($result)
        {
        global $Version;
        if(version_compare($Version,2.0,=))
                { $Ret = mysql_fetch_array($result); if(!$Ret) { } else { 
 return $Ret; } }
        else    { $Ret = odbtp_fetch_array($result); if(!$Ret) { } else { 
 return $Ret; } }
        }

 This feels like a hack but works perfectly. Data is returned and all
 is right with the world. Until I added in extra error reporting.
 When I change the if(!$Ret) portion as such...

        if(!$Ret) { die(myError.mysql_error()); } else { return $Ret; }

 It ALWAYS dies... and I see myError on the screen... If I change it
 like such...

        if(!$Ret) { } else { echo notError; return $Ret; }

 I always see the notError on the screen and $Ret gets returned.

 WHY does adding the die() inside the { } change the way the if is evaluated?

 By the way I've tested this on 4.4.x on OSX and Windows, and on 5.2.5
 on Windows...

 Thanks

 Matt

 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php



What's the output of var_dump($Ret) right before that if statement?

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Broken IF behavior? (Changing the branch changes the evaluation)

2009-07-28 Thread Matt Neimeyer
It's exactly what I would expect... The content of the row... But in
any case, what does changing the content of the { } branch have to do
with how the IF() itself is evaluated?

array(4) {
  [0]=
  string(8) CustName
  [config]=
  string(8) CustName
  [1]=
  string(11) Sample Cust
  [value]=
  string(11) Sample Cust
}


On Tue, Jul 28, 2009 at 2:56 PM, Eddie Drapkinoorza...@gmail.com wrote:
 On Tue, Jul 28, 2009 at 2:48 PM, Matt Neimeyerm...@neimeyer.org wrote:
 Background: I'm converting a webapp from Visual FoxPro as a backend to
 MySQL... However one part of our app (a system status checker) is
 common code between the versions.

 I've got the following function... In English (in case it's not
 apparent), if the version of the app is 2.0 or higher, then use MySQL
 functions, otherwise use the ODBTP function to connect to VFP.

 function my_fetch_array($result)
        {
        global $Version;
        if(version_compare($Version,2.0,=))
                { $Ret = mysql_fetch_array($result); if(!$Ret) { } else { 
 return $Ret; } }
        else    { $Ret = odbtp_fetch_array($result); if(!$Ret) { } else { 
 return $Ret; } }
        }

 This feels like a hack but works perfectly. Data is returned and all
 is right with the world. Until I added in extra error reporting.
 When I change the if(!$Ret) portion as such...

        if(!$Ret) { die(myError.mysql_error()); } else { return $Ret; }

 It ALWAYS dies... and I see myError on the screen... If I change it
 like such...

        if(!$Ret) { } else { echo notError; return $Ret; }

 I always see the notError on the screen and $Ret gets returned.

 WHY does adding the die() inside the { } change the way the if is evaluated?

 By the way I've tested this on 4.4.x on OSX and Windows, and on 5.2.5
 on Windows...

 Thanks

 Matt

 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php



 What's the output of var_dump($Ret) right before that if statement?


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php