Logging from a PHP Notice

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
SpecialK
Forum Commoner
Posts: 96
Joined: Mon Sep 18, 2006 3:49 pm

Logging from a PHP Notice

Post by SpecialK »

Glad to see I can finally get my DNS to find the site! It's been hectic few days searching for help, so maybe someone here can shed some light on my problem.

I have some legacy code that is present on a live program.

The error I get is:
[client x.x.x.x] PHP Notice: Undefined offset: 3 in /.../x.php on line 70
by the line:

Code: Select all

list($a,$b,$c,$d) = split(":", $retValues);
Now this is a DB query from a delimited list that is returned. How can I find out more information about this issue when the PHP Notice is thrown? I was thinking something similar to a try/catch to get the information, but wasn't sure. My initial idea was a function like if(PHP_NOTICE) or something like that to run something when the Notice is thrown.

What would be the best solution to find out what is actually being set in $retValues (only when the issue happens). I can't feasibly do it everytime because it is a live program now. It's not an issue the users themselves notice, but I would rather clean up the code to the best possible. I don't want any coding errors to be in the logs.
alex.barylski
DevNet Evangelist
Posts: 6267
Joined: Tue Dec 21, 2004 5:00 pm
Location: Winnipeg

Re: Logging from a PHP Notice

Post by alex.barylski »

http://ca3.php.net/manual/en/function.s ... andler.php

So the error is being caused when $retValues doesn't have the proper number of delimited values?

Personally I would just supress the error (if legacy code) or write a script to fix the database by ensuring each field has the proper number of ':' delimiters so that each list() = split() at least returns empty values...

Cheers :)
User avatar
SpecialK
Forum Commoner
Posts: 96
Joined: Mon Sep 18, 2006 3:49 pm

Re: Logging from a PHP Notice

Post by SpecialK »

I "could" suppress the error, but this is legacy code that I created over a year ago. I believe it's up to me to fix it.

I am currently implementing a way to email me the $retValues so I can see the actual array and try to debug. The script it's calling from delimits everything by the colon, so even blank fields should be fine. Maybe they aren't, I believe when I see a full variable dump of $retValues then I will understand more what the issue is.
Post Reply