6 Common error tips and solutions for PHP _php tips

Source: Internet
Author: User
Tags apache error log install php parse error php code php error

In the PHP development process, because do not know who to ask for help and distraught to judge that they are not suitable for learning PHP. In fact, mistakes in everyone's learning process will encounter, do not underestimate yourself. Many errors in the error in the code hint has been told us, carefully look, will not Baidu. Some common PHP errors are summarized to share PHP newcomers.
PHP Common Error Tips

First, Fatal error:call to undefined function ...
function does not exist, possible causes :
1, the system does not exist this function and you do not have a custom
2, some people will ask, I do not complain on other machines. That is because the environment is different, this function is not open in this machine, how to open? You Baidu function name, you can find this function belongs to which DLL, to php.ini open.

Example Explanation: PHP FATAL Error:call to UNDEFINED FUNCTION Bcmul () solution

When a server that handles network payments is migrated, it is found that it cannot be paid.

PHP Environment:
PHP version for 5.3.3
System for Red Hat 4.1.2-54
Check the Apache error log and find that a function in the encrypted file Bcmul () complains:

Copy Code code as follows:
PHP Fatal error:call to undefined function bcmul () in/php_rsa.php in line xxx

Solution:
use the following command:

Copy Code code as follows:
Yum Install Php-bcmath

It's ready for installation.

If the following conditions occur:

Copy Code code as follows:

Loaded Plugins:fastestmirror
Loading mirror speeds from cached hostfile
* base:mirrors.yun-idc.com
* extras:mirrors.yun-idc.com
* rpmforge:ftp.riken.jp
* updates:mirrors.yun-idc.com
Setting up Install Process
Resolving dependencies
--> Running Transaction Check
---> Package php-bcmath.x86_64 0:5.1.6-40.el5_9 set to be updated
--> processing Dependency:php-common = 5.1.6-40.el5_9 for Package:php-bcmath
--> Running Transaction Check
---> Package php-common.x86_64 0:5.1.6-40.el5_9 set to be updated
--> Processing Conflict:php53-common Conflicts Php-common
--> finished Dependency resolution
Php53-common-5.3.3-13.el5_9.1.x86_64 from installed has depsolving problems
--> Php53-common conflicts with Php-common
Error:php53-common conflicts with Php-common
You could try-using--skip-broken to work around the problem
You could try Running:package-cleanup--problems
Package-cleanup--dupes
Rpm-va--nofiles--nodigest

You need to use Yum Update, then yum install Php53-bcmath.

By the way, Bcmath this function is one of the PHP math extensions. You can use Bcscale () to set the global default number of decimal places, as follows:

Copy Code code as follows:
String Bcmul (String $left _operand, String $right _operand [, int $scale])

Example:

<?php
Echo bcmul (' 1.34747474747 ', ' 3 ');//47.161
echo Bcmul (' 2 ', ' 4 ');//8
?>

Options for this function in php.ini:

Copy Code code as follows:

[Bcmath]
; Number of decimal digits for all Bcmath functions.
; Http://www.php.net/manual/en/bc.configuration.php#ini.bcmath.scale
Bcmath.scale = 0

Second, syntax error, unexpected t_string, expecting ...
serious grammatical errors, such as syntax error, unexpected t_string, expecting ', ' or '; ' in F:\phpnow\htdocs\index.php on line 4
Check the punctuation on the line by yourself.

If the third line is not in the back of Echo 1, the error will be in line 4 and on lines 4, the fourth.

Example Explanation:

In fact, this is a very easy to solve the problem. In my opinion, déjà vu, hehe, recently learned JavaScript but learned to use VAR to declare variables.

In fact, there is no need to use the Var declaration in PHP, but when a variable as a member of a class variable , the use of Var is not a problem.

Use VAR on the outside error parse Error:syntax error, unexpected T_var in ..., for example, my error message:

Parse error:syntax error, unexpected T_var in D:\Apache2.2\htdocs\shirdrn\page\p2\pageUtil.inc on line 34

I'm testing: Inside a class, an error occurs when you use a class object of your own definition as a member of this class.

The address class corresponds to the Address.inc code:

<?php
class Address {
var $road;
function address () {}
function Setroad ($road) {
$this->road = $road;
}
}
? >

The person class and its test code are person.php as follows:

<?php
require ("Address.inc");
Class Person {
var $name;
var $address;
function person () {
}
function display () {
echo "Name:". $this->name. " <BR> ";
echo "Road:". $this->address->road. " <BR> ";
}
}

var $p = new Person ();
$p->address = new address ();
$p->address->setroad ("Chagnchun Road");
$p->name = "Shirdrn";
$p->display ();
? >


An exception occurred in the Test loss:

Parse error:syntax error, unexpected T_var in D:\Apache2.2\htdocs\shirdrn\page\p2\pageUtil.inc on line 34

Just because you use VAR to declare variables in person.php code, you can't do this in PHP, as long as you start with the "$" symbol to indicate that the character is followed by a PHP variable.
Oh:-)
Other user's Supplementary method:
Problem Resolution: syntax error, unexpected t_string, expecting t_old_function or t_function or T_var or two days before starting their own PHP trip, do a very common site, resulting in our ph P is version 5.0, the server is 4.0 version, and I wonder if it's dead. Yesterday was a busy day, and this morning came, in an article found out, the solution. Parse error:syntax error, unexpected t_string, expecting t_old_function or t_function or '} ', if "public", will "pub Lic "removed. There is no error, if "public" is defined variable, change "public" to "Var".

Third, Parse error:syntax error, unexpected t_variable in xxx.php on line XXX
This statement is a common error in PHP, usually on the line of XXX line, or xxx line, missing a semicolon. or use double quotes in double quotes, without escaping, and so on.
Solution: Find xxx.php's XXX line, according to the above analysis, to find their own mistakes, to correct.
Tip: As a programmer, to do code rigorous, clear thinking, and careful. Err, but try to avoid these mistakes because of carelessness, so as to become qualified programmers.

Iv. Parse error:syntax error, unexpected ' X ' in xxx.php on line XXX

This statement is still a common PHP error, the error is due to the xxx line in xxx.php, the occurrence of PHP unrecognized characters. Often because the function,if such as the need for ' {', '} ' where there is no closure, or in the programming, careless in '; ' Several characters were mistakenly played on the back.
Workaround: Find xxx.php's XXX line, remove the extra characters, and add the missing characters.

V. Syntax error, unexpected $end
logic forgot to close this error also has a feature, he will prompt you the last line of code error, for example, you have 30 lines, he told you on line 30, this time you do not check the 30th line, you have to take 30 rows, check again, to see which tag is not closed.
A total of 3000 lines, he tells you on line 3000, this time you do not check the 3000 lines, if your program layout is messy, in 3000 lines to find which bracket is a very troublesome thing ... I'll teach you a trick:Ctrl + a ctrl+d ALT+F4
Well, you can rewrite it now.

Another way of thinking:

Parse error:syntax error, unexpected $end in script.php at line xx
After debugging for a while, you find that the row that generated the error is a row in the middle of the file
//$str. = ">\n";
I remember. The end tag allowed by the PHP interpreter the line can also be in a single comment, i.e.//$str. = ">\n"; is interpreted as a note before the end tag, and the content of the comment is//$str. = ", and?> behind \ n"; will be interpreted as the contents of the PHP block outside the HTML output! The result is to $str. = ">\n"; This line adds//becomes a comment, instead of a?> end tag, causing the original real end tag to be unexpected (unexpected).
The solution is to simply delete the line.
PHP start and end tag rows don't write anything else, it's a good habit.

Vi. notice:undefined varialbe: ...
This is a more common error, the workaround: error_reporting to adjust the error level,

The above is for you to share the common PHP 6 error tips, to provide you with a general idea of the solution and direction, I hope to help you learn.

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.