I'm writing a function that can returns an integer value or write this integer into a file. I want this choice to be done just by the call of the function. Can I do it ?
Here is the function :
function directory_space_used($directory) {
// Space used by the $directory
...
if ( "call #1" ) return $space_used;
if ( "call #2" ) {
$file=fopen(path/to/file, 'w');
fwrite($file, $space_used);
fclose($file);
}
return null;
}
Call #1 :
$hyper_space = directory_space_used('awesome/directory');
echo "$hyper_space bytes used.";
Call #2 :
directory_space_used('awesome/directory'); // Write in file path/to/file
If it's not possible, I can use a 2nd parameter in the function but I want to keep the parameters' number as low as possible.
Thanks.