You are here: Re: [PHP] this may be a daft question but.....defining indexes « PHP « IT news, forums, messages
Re: [PHP] this may be a daft question but.....defining indexes

Posted by "Thorsten Suckow-Homberg" on 09/20/05 00:51

> This may be a daft question but I keep getting notices on undefined
> indexes


I'm sorry to tell you, but this implies bad programming-practice. ;)

First off: Leveling the error_reporting in the php-ini is NOT a good idea!
Have you ever tested osCommerce with error_reporting set to E_ALL? You
better don't!

So get used to write your applications in error_reporting E_ALL, because
this will inform you of every not properly intialized var you are using.

Back to the index-problem:

The best way to check the indizes is:

$p = isset($myArray['this_index_doesnt_even_exist']) ?
$myArray['this_index_doesnt_even_exist'] : null;

This will check if the index in the given array exists: If, the value will
be assigned to the var $p, else null will be returned, thus $p holding null
(or any other value you want to assign per default). This will prevend
error-output. For more information read the isset()-entry in the official
php manual.

However, if you are using a third party app and want to get rid of this
annoying messages, you can tell php not to output E_NOTICE or E_WARNING
levelled messages. You can do this by editing the php.ini-parameter
"error_reporting". But basically, this is something you should never ever
do. Your code should run clean even with error_reporting set to E_ALL.

Best regards


Thorsten Suckow-Homberg

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация