Fatalerror: Calltoundefinedfunction_PHP tutorial

Source: Internet
Author: User
Fatalerror: Calltoundefinedfunction. Fatal errors of common PHP errors (1) ---- undefined function I. Error Type: PHP fatal error Errortype: PHPFatalerrorFatalerror: Calltoundefinedfunction (a) in (B) on PHP common error handling fatal error (1) ---- function undefined

I. Error Type: PHP fatal error

Error type: PHP Fatal error

Fatal error: Call to undefined function (a) in (B) on line (c)

II. error description:

This error report indicates that you are calling undefined functions.

A ---- indicates the undefined function name;

B ---- path of the script section;

C ---- attempt to call the row number of the undefined function.

D ---- the row number when the function is defined for the second time.

III. causes and solutions:

Cause 1: You have not declared this function. For example, directly call the following function

MyFunction (); // This function is not available at all.

The result is as follows:

Fatal error: Call to undefinedfunction myFunction () in (path) on line 1

Solution:

Check whether the function is declared in your program.

Cause 2: The name you used in the function declaration is different from the name you used in the call. for example:

Function myFunction () {// do something} myFuntion (); // a letter c is missing.

Solution: This is the easiest mistake for many beginners. Sometimes it takes a long time to check whether a letter is missing or not written.

Cause 3: errors generated when you call the new PHP built-in functions in the old version of PHP. Because this PHP built-in function does not exist in your old version. For example, you call mime_content_type () in the old PHP version ()

Fatal error: Call to undefinedfunction mime_content_type ()

Solution: Open the PHP manual and carefully check which built-in functions are applicable to PHP. The PHP Manual specifies detailed version limits for each built-in function. For example (PHP 4> = 4.3.0, PHP 5). Therefore, the solution is to upgrade your PHP version or change other built-in functions of the same type.

Cause 4: Your code for calling the function is written in a file different from the function declaration. For example, you have written such code in the. php file.

MyFunction ();

Your function declaration is in B. php.

Function myFunction () {// do something}

Solution: This usually happens to PHP beginners who forget that PHP will not automatically associate or reference files when calling functions. That is to say, in the above case, a. php and B. php do not have any relationship at all. At this time, you need to use functions such as include () to associate the two.

Cause 5: Your code for calling the function is written in a file different from the function declaration. you have also introduced this file. However, your function call code is located before the file code is introduced. For example, if you execute a function call in a. php and declare a function in B. php

A. php code

MyFunction (); include ('B. php ');

B. php code

Function myFunction () {echo '000000 ';}

Solution: as shown in the preceding code, an error is reported during execution. Because PHP cannot find the declaration of the function when executing the function call. Therefore, do not write the function call before the function declaration file is introduced. Of course, if you are in the same PHP file, you can write the called function before the function declaration.

Cause 6: You define a function using the same name twice in a row, for example

Function myFunction (){}

Function myFunction (){}

The result is as follows:

Fatal error: Cannot redeclare myfunction () (previously declared in (path): 2) in (path) on line 1

Solution:

Find the declared function and see what causes you to define it again. If you simply forget that you have previously defined the statement, delete it. Of course, your situation may be complicated. For example, if the arrangement of your script files is exceptionally messy and you may use a large number of include () functions, it will make it difficult for you to clarify your ideas from the chaotic code.

Evaluate (1) ---- function undefined 1. Error type: PHP Fatal error Fatal Error: Call to undefined function (a) in (B) on...

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.