THE ZEPINT NETWORK

programmer assist

PHP PHP XML Feeds

PHP Questions PHP Solutions PHP Articles

PHP is a popular open-source programming language used primarily for developing server-side applications and dynamic web content, and more recently, other software. The name is a recursive acronym for "PHP: Hypertext Preprocessor".

The Most Common PHP Programming Errors..

DiggBlinkRedditDeliciousTechnorati

question by Bejaan | Easy

Please list what you think are the most common PHP coding errors. Thanks!

- Bejaan

Post reply Subscriptions

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 Srirangan

Here's the Zend's List of the Top 21 PHP Programming Errors: http://www.zend.com/zend/art/mistake.php

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!

Search via Google

User Login

Email Address

Password

PHP Experts

Rank Expert Points
#1 Srirangan 2650
#2 Anurag 600
#3 mastercomputers 100
This a list of the Top PHP experts, how many points do you have?

Leading Experts

Rank Expert Points
#1 frankzzsword 4600
#2 Bejaan 2900
#3 csfreak 1100
#4 Anurag 700
#5 keyvez 700
#6 nnarasimha 600
#7 Nakata 600
#8 martinig 600
#9 mastercomputers 400
#10 Huntress 150
#11 Adkron 150
#12 Yogesh 100
#13 lexxwern 100
#14 Mustan Khan 100
#15 poizn 100
This is a list of overall best performing experts, how many points do you have?