note 44056 added to language.operators.errorcontrol

From: Date: Tue, 13 Jul 2004 21:04:17 +0000
Subject: note 44056 added to language.operators.errorcontrol
Groups: php.notes 
Request: Send a blank email to php-notes+get-73186@lists.php.net to get a copy of this message
To avoid all the "Notice: Undefined index: ..." with error_reporting(E_ALL) when incrementing an undefined array index, try the following function instead: <?php error_reporting(E_ALL); $array1['newindex1']++; // Notice: Undefined variable: array1 in /home/user/www/test.phtml on line 4 // Notice: Undefined index: newindex1 in /home/user/www/test.phtml on line 4 incr($array2['newindex2']); // no notice. $array2['newindex2'] set to 1. function incr(&$var, $amt = 1) { // note the pass by reference if (!isset($var)) {$var = $amt;} else {$var += $amt;} } ?> ---- Manual Page -- http://www.php.net/manual/en/language.operators.errorcontrol.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+44056 Delete -- http://master.php.net/manage/user-notes.php?action=delete+44056&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+44056&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#73186) next »