Link to home
Start Free TrialLog in
Avatar of karakash
karakash

asked on

Fatal error: Cannot redeclare file_put_contents()

Following function giving out error Fatal error: Cannot redeclare file_put_contents(). Can someone tell me what might be wrong with the statement? It was working fine in PHP4 but after upgrading server to php5 its giving the error.

function file_put_contents($n, $d, $flag = false) {
    $mode = ($flag == FILE_APPEND || strtoupper($flag) == 'FILE_APPEND') ? 'a' : 'w';
    $f = @fopen($n, $mode);
    if ($f === false) {
        return 0;
    } else {
        if (is_array($d)) $d = implode($d);
        $bytes_written = fwrite($f, $d);
        fclose($f);
       return $bytes_written;
}
}
Avatar of ray-solomon
ray-solomon
Flag of United States of America image

file_put_contents() is a core php function name.
http://us2.php.net/file_put_contents

You just need to rename your custom function to something different, then update the references to that function in your code.

You should have got the same Fatal error in php4, so this means the display_errors was off in your php.ini or this script.
ASKER CERTIFIED SOLUTION
Avatar of ddrudik
ddrudik
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Or you can just use the core function instead since it does the same as your custom function.

file_put_contents($filename, $data, FILE_APPEND);
Avatar of karakash
karakash

ASKER

changing the function name giving the same error.
Check to see if your function is within a loop.

If it is, then take it out of the loop.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial