From: "Scot L. Harris" <[EMAIL PROTECTED]>

> I came across an interesting problem today which I have found a work
> around but was wondering if anyone on the list had a better way to solve
> this problem.
>
> Been writing some php scripts on a Linux system using PHP 4.2.2.  Basic
> script works just fine there and does what is needed.
>
> Moved this script over to a system running PHP 4.3.6 (and subsequently
> to one running PHP 4.3.4) and found the script dumping a tremendous
> number of warning messages.
>
> Tracked this down to my use of arrays and the list and explode
> functions.
>
> working example code follows:
>
> <?php
>
> $arrayvalues = array("alpha" => 1, "beta" => 2, "gamma" => 3);
>
> $data = array("alpha=first", "junk", "beta=last");
>
> $numvalues = count($data);
>
> for($i=0;$i < $numvalues;$i++)
> {
> @list($parameter, $value) = explode("=",$data[$i]);

When explode() hit's the "junk" entry, a one element array is going to be
returned when list() is looking for two. So that'll be causing your
warnings.

Why use list?

foreach($data as $value)
{
    $part = explode('=',$value);

    if(count($part) != 2)
    { echo "array value did not have = sign"; }
    else
    {
        if(isset($arrayvalues[$part[0]]))
        ...
    }
}

> I was wondering if there is a better way to handle the error message
> from the list() function other than just ignoring it.  Or going
> overboard and creating my own error handling functions.

You could always just resort to

error_reporting(E_ALL ^ E_NOTICE)

at the beginning of your script and be done with this. :) But that's
cheating.

---John Holmes...

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to