Re: this may be a daft question but.....defining indexes

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux