$fullcont3 = 'content/content1.txt'; $article3 = ''; if (file_put_contents($fullcont3, $article3) === TRUE) { echo "TRUE"; } else { echo "FALSE"; } 

// Returns FALSE but the file is written

// Actually the question is why does FALSE return?

I think because, returns the number of bytes written to the file, in this case will return 0, and 0 === FALSE

  • 0! == FALSE. Identity is a test for equality, taking into account the type - mkardakov
  • Well, so it seems that 0 is equal to FALSE with regard to the type - hovdev
  • @ S1lllver, type number cannot be equal to type of boolean value. - Alex Krass
  • yes, exactly what I am talking about - hovdev
  • did not notice the string "when converting to boolean" When converting to boolean, the following values ​​are treated as FALSE: the value itself is boolean FALSE integer 0 (zero) - hovdev

2 answers 2

file_put_content Returns either the number of bytes (a number) or FALSE.

It never returns true.

Given the identity check, the first If is never executed.

  • will return TRUE if === replaced by == and '' replaced by '1' - hovdev
  • one
    the method does not return true. he will bring it to true in this case, if you use the comparison - mkardakov
  • that's what I wanted to say plus - hovdev
 if (file_put_contents($fullcont3, $article3) === FALSE) echo "Запись не удалась"; else echo "Запись удалась";