Avoiding NOTICEs with list()

From: Date: Mon, 24 Jan 2005 20:54:45 +0000
Subject: Avoiding NOTICEs with list()
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-207169@lists.php.net to get a copy of this message
This construct: list($v1, $v2, $v3) = explode($sep, $string, 3); will generate NOTICE level errors if there are not enough parts of the string to fill all the variables in the list. What I really want is for list() to set the variables that have a corresponding array element, and then either don't change the others, or set them to NULL -- I could live with either approach. Anyone see a way to get rid of these errors short of this approach: $parts = explode($sep, $string, 3); switch(count($parts)) { case 3: $v3 = $parts[2]; case 2: $v2 = $parts[1]; case 1: $v1 = $parts[0]; } I did try @list(... and it made no difference. Thanks, -- Tom

« previous php.general (#207169) next »