Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Good Practice to get rid of ALL Notices ?? 2

Status
Not open for further replies.

sen5241b

IS-IT--Management
Sep 27, 2007
199
US
Is it really a good programming practice to deal with or get rid of ALL Notices in your PHP?

I get these a lot:

Notice: Array to string conversion in /home/content/f/r/e/fred111/html/myfolder/tects2.php on line 147
 
Yes, its always a good practice to not have any warnings present.
As you could be performing operations on the wrong data.

When arrays are used as string, like if you attempt to print for instance:

echo $myrray;

You get the word "array" instead. So any string operations would likely be performed on that word instead of whatever string you actually want to perform them on.
You'll get the warning, but the operation will proceed.



----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Behind the Web, Tips and Tricks for Web Development.
 
The following line of code, which, outputs an array into a log file is causing: "Notice: Array to string conversion in ... etc.php"

Code:
DebugToLog('DEBUG: FRs retrieved. FRs to be used in array=' . implode(' ', $FRArray));

How would you change this to get rid of the notice?
 
i suspect that $FRArray itself contains arrays. try this instead

Code:
DebugToLog('DEBUG: FRs retrieved. FRs to be used in array=' .print_r($FRArray, true));
 
I agree with jpadie, its likely your $FRArray variable contains additional arrays. If you really need to have the contents $FRArray as a comma separated string, then you'll need to go through it and use is_array() to determine which of the keys is an array itself and implode it too; which can get a bit complex if you have more arrays within arrays inside the $FRArray.

The print_r method will offer a viewable string without any fuss, but it won't be comma separated.




----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Behind the Web, Tips and Tricks for Web Development.
 
That was it -array within arrays. print_r output is rather verbose in a log file though. thx
 
you could try serialize. or roll your own function in place of print_r.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top