Reputation: 422
I have code similar to the following in PHP:
if(move_uploaded_file($tempfile, $newfilelocation) && functionReturningFalse()) {} else {...}
Let's say the first function returns true (successfully moves the uploaded file) and there is some second function that returns false. Why is the file not being moved? If I remove the second function call the file will move to its new location fine.
***Edit: I am not asking why the code inside the braces {} would not be running. It is my thought that the php move_uploaded_file function should be moving a temporary file when it is called, even if the function called beside it (functionReturningFalse()) returns false. This is not the case. If the second function returns false, my file is not moved.
Upvotes: 1
Views: 108
Reputation: 60414
If I remove the second function call the file will move to its new location fine.
You are on the wrong path. I don't know what's changing the behavior (or if it is changing at all), but in general, the return value of any function call on the right-hand side of the &&
will not change the behavior of the function call on the left-hand side of the &&
.
It is possible for the body of one function to undo or otherwise interfere with the results of a previous function call, but it doesn't sound like that's what is happening here. And even if this were the case, it wouldn't have anything to do with the second function's return value.
Upvotes: 0
Reputation: 1182
if((move_uploaded_file($tempfile, $newfilelocation)) && ! (functionReturningFalse())) {} else {...}
Upvotes: 0
Reputation: 7053
if (true && false) {
echo 'both true';
} else {
echo 'one or both false';
}
See the ! (NOT)
if (true && ! false) {
echo 'both true';
} else {
echo 'one or both false';
}
or be explicit... if(move_uploaded_file($tempfile, $newfilelocation) == true && functionReturningFalse() == false) {
Upvotes: 0