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);
       return $bytes_written;
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

file_put_contents() is a core php function name.

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.
karakash, that's a name reserved for a PHP function:

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day 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);
OWASP: Avoiding Hacker Tricks

Learn to build secure applications from the mindset of the hacker and avoid being exploited.

karakashAuthor Commented:
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.
Your error message means the function is being called more than once during the execution of the script.

You can also check if your function is being included in your script more than once.
Sometimes this happens if you include multiple php scripts together into your main php script and one of those scripts is also calling the same function.

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.