Re: Avoiding NOTICEs with list()
| From: | James Kaufman | Date: | Mon, 24 Jan 2005 21:40:25 +0000 |
| Subject: | Re: Avoiding NOTICEs with list() | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-207175@lists.php.net to get a copy of this message | ||
On Mon, Jan 24, 2005 at 03:54:45PM -0500, trlists@clayst.com wrote:
> 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.
I just tried it with php 4.3.8 and it did not throw a NOTICE with @list.
I suppose you could try @explode as well as @list.
--
Jim Kaufman
Linux Evangelist
public key 0x6D802619, CISSP# 65668