2

why does this not work?

if($result = $db->execute($params) && $result->rowCount() > 0)

I get an error when the $db->execute fails that $result is a non-object.

of course it is. $result equals FALSE so it should skip the rowCount check shouldn't it?

4

1 に答える 1

5
if($result = $db->execute($params) && $result->rowCount() > 0)

と同じです

if($result = ($db->execute($params) && $result->rowCount() > 0))

やったほうがいい

if(($result = $db->execute($params)) && ($result->rowCount() > 0))

または、さらに良い:

$result = $db->execute($params);
if($result && $result->rowCount() > 0)
于 2013-06-21T21:29:24.853 に答える