Re: The Most Common PHP Programming Errors..reply by Srirangan Here are some I think are very common:
Warning: Invalid argument supplied for foreach() in /www/yourserver/html/script.php on line 36
This warning implies that the first variable in your foreach statement is not an array. If your statement is foreach($a as $b), $a, the first variable, needs to be an array.
Parse error: parse error, unexpected $ in /www/yourserver/html/script.php on line 36
Check to see if there is a missing curly brace from your for, while or if?else loop.
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /www/yourserver/html/script.php on line 36
This warning message means that the variable that?s being used in mysql_fetch_array() is not the variable that is holding the result of the sql query. If your query was stored in the variable $eg (e.g.: $eg=mysql_query("SELECT * FROM table");), then you would fetch the array like this: mysql_fetch_array($eg);
Warning: Cannot modify header information ? headers already sent by (output started at /www/yourserver/html/includedfile.php:4) in /www/yourserver/html/script.php on line 36
This implies that you have some kind of HTML, XML, or white space at the top of your PHP script that was sent to the browser following your server?s response headers. The ?output started at ?? phrase lets you know which file and line number (in this case, line 4) contains the offending code/whitespace.
Post reply
Subscriptions
Re: The Most Common PHP Programming Errors..reply by lexxwern Here's a good list...
Common errors
A very large percentage of errors are actually quite simple to spot and solve once you are sufficiently experienced, however they continue to crop up time and time again to plague us. This next section includes hints and tips on how to solve specific common problems in code - if you are encountering an error in your script that you just cannot track down, see if you find your answer here.
19.12.3.1 I see the source code of my PHP script
This normally occurs when you have misconfigured Apache; check your install and try again.
19.12.3.2 My script does nothing
If you don't get the output you were expecting, it is possible that you have an invisible error somewhere. There are two ways to check this is not the case:
1. Check your php.ini file and make sure "display_errors" is set to On.
2. If your script is output content inside a HTML page, the errors may be obscured by the HTML - use the View Source functionality of your browser to search for "PHP". This should bring up any errors, if there are any.
If you still have nothing, try these possibilities:
* Make sure you don't have output buffering hiding your output
* Make sure "error_reporting" is set to E_ALL in your php.ini file
* Make sure you have saved the latest version of your script
* Make sure all your includes are working
If you are still having trouble, you need to seek out others to help.
More at: http://www.hudzilla.org/phpbook/read.php/19_12_3
Post reply
Subscriptions
Re: The Most Common PHP Programming Errors..reply by VGR I agree to all the above(*), but as an experienced PHP developer, I have other classical errors in my list :
- invalid argument type when you inverse strpos() arguments, as they are in a different order than in_array() etc - there is no consistency in PHP about the order of arguments by type (needle, haystack).
- "PHP Notice: Undefined index: region in " : you access an invalid element of an associative array
- "PHP Warning: failed to open stream: No such file or directory in" : bad I/O = file missing with given path
- "PHP Fatal error: Maximum execution time of 480 seconds exceeded in " : you have an infinite loop, OR there is a bottleneck and your script needs more time to run to completeness.
- "PHP Notice: Undefined variable: lesmess in" : you used an undefined variable for an operator .= (concatenation on string) or with []= (array) or with an arithmetic operatopr on a scalar variable. Define/initialize the variable
- "PHP Warning: mail(): Failed to connect to mailserver at" : transient connectivity problem, OR you have a bad SMTP settings in your php.ini
See ya on EEE.org (www.europeanexperts.org)
(*) Sri, for "unexpected $ in" you forgot the "space after end marker" or "bad end marker" classical errors when using the Heredoc syntax.
Post reply
Subscriptions
Re: The Most Common PHP Programming Errors..reply by Nilesh forgetting $ in var name is most common error.Also sometime forgetting encryption type in form of uploading program is most common error.
Post reply
Subscriptions
Got a PHP Question?
Just Sign Up and ask the top PHP experts!
|