-1

Is there a way to make php notices more informative? For example, I'm getting notices such as

Notice: Undefined offset: 1 in /home/anon/public_html/MotE/lib/Bullet.php on line 18

while running file() to store each line in an array and then exploding each line in the array by \t. Is there a way to have the notice show me which line in the file I'm reading from is causing the issue?

I would like to know if there is a way to make php notices more informative?

Perhaps something like

Notice: Undefined offset: 1 in /home/anon/public_html/MotE/lib/Bullet.php on line 18 [File: /feed.csv]

If I do something like

echo 'line: ' . $arrKey . '<br />';

the notices all disappear but echoing that much information is undesirable and provides no useful information since the notices disappear.

Nate
  • 259
  • 1
  • 6
  • 18
  • 3
    what is the question? solving that error? or getting more comprehensive error messages? maybe try xdebug – Kevin Sep 12 '14 at 03:46
  • 1
    In that case, you know it's the *second* item in your array that is the problem (arrays being 0-indexed). Sometimes it's about being familiar with php's sometimes weird messages (Paamayim Nekudotayim anyone?) – willoller Sep 12 '14 at 03:49
  • Yes but not every line drops a notice...only certain ones. – Nate Sep 12 '14 at 03:52
  • So what you are looking for is error checking - like `if (is_valid_thing($thing)) { do_work(); } else { /* throw a nice error */ } – willoller Sep 12 '14 at 03:53
  • Yes that would work if I can find out which line of the feed.csv was being read just before the undefined offseet. – Nate Sep 12 '14 at 03:55
  • @nate this notice is very very informative. First i used to think like you but keep on learning these message actually tell you in 90% of the cases what you are doing wrong. undefined offset 1, means that value for index or offset one does not exist. Thanks – arif_suhail_123 Sep 16 '14 at 02:53
  • if you post your code i might be able to tell, how to make it disappear without echoing out any thing. Thanks – arif_suhail_123 Sep 16 '14 at 02:55

1 Answers1

1

You can look at Xdebug - it will print backtrace for you. More info here: How can I get PHP to produce a backtrace upon errors?

Community
  • 1
  • 1
Timur
  • 6,668
  • 1
  • 28
  • 37