Fatal error:cannot redeclare dbconnect () (previously declared in D

Source: Internet
Author: User
Tags error handling

Fatal error:cannot redeclare db_connect () (previously declared in D:/wamp/www/flex/new/mysql_inc.php:7) in D:/wamp/www/ flex/new/mysql_inc.php on line 20

The workaround is as follows:

1. Do you have an include or require in the source code containing the other file functions contained in the file contains the definition of the NW () and this code has the definition of NV () so there are Redeclare (duplicate declaration/definition) of the error
2. PHP contains two files with the same name function, what will happen?
Answer:

(1) will be an error:

(2) will prompt fatal Error:cannot redeclare function name that is, you have repeatedly declared it. Include or require change to include_once or require_once

The following refers to its address: http://www.chinabaike.com/z/jd/2012/0428/1105996.html related instructions:


Fatal errors for common error handling in PHP (ii)----Duplicate definition function


One, error type: PHP fatal error
Error type:php Fatal error
Fatal Error:cannot Redeclare (a) (previously declared in (b)) in (c) to line (d)

Second, the error description:
This error report indicates that you are attempting to redefine a function that has already been defined, where
A----the name of the function that represents the duplicate definition;
b----The name of the file and the line number for the first time the function is defined;
C----The name of the file the second time the function was defined;
D----The line number when the function is defined for the second time.

Iii. Reasons and Solutions:
Reason: You use the same name for two consecutive times to define a function, such as
function MyFunction () {} function MyFunction () {}
The results are as follows
Fatal error:cannot redeclare myfunction () (previously declared in (path): 2) in (path) to line 1
Solve:
Find the function you've already declared, and see what needs to lead you to define it again. If you simply forget what you have already defined before, delete one of the statements. Of course, your situation may be complicated. For example, your scripting files are cluttered and you might use a lot of functions such as include (), which can make it difficult to sort out your thoughts from confusing code.
However, if your PHP version is newer (PHP 5.3.8+) It looks like you can use namespaces to solve the need for duplicate-defined functions. Since this is not too certain, so do not do too much discussion here.


(2) will prompt fatal Error:cannot redeclare function name that is, you have repeatedly declared it. Include or require change to include_once or require_once

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.