File_put_contents() "The output of functions that don't return anything should not be used"


The output of functions that don’t return anything should not be used

if(file_put_contents($target_path.$filename, $img)){ documentation: “This function returns the number of bytes that were written to the file, or false on failure.”

Hi @tbessenreither and welcome to the community,

Can you provide more context or a specific request? How do you expect the rule to behave?


the rule says i should not use the result of file_put_contents() to check in the condition because there is no return value. But file_put_contents() does in fact return a value that can be checked to see if the file was written or not.
So basically file_put_contents should not be in a list of functions without return values or something.

Hi @tbessenreither,
I can’t reproduce the issue with your given line. file_put_contents is not part of the void function built in list.

Are you trying to override this function somehow? Are you getting a secondary location for this issue? Can you give a bit more context to this line?

We get this message on all our file_put_contents functions.

most recent example:

$return = file_put_contents($filetarget, $pdf_data);
if (!$return) {
    return false;
} else {
    return true;

The message is php:S3699 of the default sonar-way php rules:
Remove this use of the output from “file_put_contents”; “file_put_contents” doesn’t return anything.
The output of functions that don’t return anything should not be used