Re: [PHP] Undefined offset on Windows not on Apache?

From: Chris Williams (chris_at_escaperadius.com)
Date: 11/30/03


To: php-general@lists.php.net
Date: Sun, 30 Nov 2003 13:32:39 -0800

I don't believe the disputed line of script is being executed because just
before that line I include the following print statement,
echo "array size: " . count($zip_forward) . " ID: $location_id<br>";
which does not get executed when my conditional fails.

Right you are on the error reporting, I included error_reporting (E_ALL); in
my test script and can reproduce same error on Apache.

Chris

"John W. Holmes" <holmes072000@charter.net> wrote in message
news:3FCA2F4C.3090206@charter.net...
> Chris Williams wrote:
> > The first and last lines contain carriage returns. The second or middle
line
> > contains sample data.
> >
> > The script that reads and parses the data is:
> >
> > $countLines = fopen("data.txt", "r");
> > while (!feof($countLines))
> > {
> > $newLine = fgets($countLines, 1024);
> > echo "line length: " . strlen($newLine) . "<br>";
> > if(strlen($newLine) > 0)
> > {
> > $newLine = ereg_replace ("\"", "", $newLine);
> > $zip_forward = explode(",",$newLine);
> > $location_id = trim($zip_forward[0]);
> > echo "array size: " . count($zip_forward) . " ID: $location_id<br>";
> > $zip_to = trim(substr($zip_forward[1], 0, 5));
> > }
> > }
> > fclose($countLines);
> >
> > What's odd here is that the last line, which has a length of 0, should
never
> > cause the if(strlen($newLine) > 0) to execute the lines of script
contained
> > within the if conditional. And in fact the lines DON'T get executed.
> > However, on the Windows server I get the following error
> > PHP Notice: Undefined offset: 1 in \debug.php on line 20. This points to
my
> > code that evaluates the second element of the array $zip_to =
> > trim(substr($zip_forward[1], 0, 5));
> >
> > If I never evaluate the $zip_forward[1] array element within the if
> > conditional, why would PHP test the array $zip_forward for the proper
number
> > of elements?
>
> Okay, if you're getting that NOTICE then the line of code is executing.
> So even though you think the strlen() line is failing, it's not.
>
> Anyhow, the whole issue here is just that your two servers have
> different error_reporting() levels. One is set to show NOTICES while the
> other is not. If you use @trim(...), you can suppress this warning.
>
> The code is running the same on both servers, though...
>
> --
> ---John Holmes...
>
> Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/
>
> php|architect: The Magazine for PHP Professionals – www.phparch.com



Relevant Pages

  • Re: Using the internet to crack codes?
    ... > parallel nature of the internet to crack codes? ... > do is run a simple script on many servers and have all scripts report ... > executing your script. ... Given that you are executing your ...
    (sci.crypt)
  • Jumpstart: syntax error and trying to load from /cdrom media, which disk to use for Solaris 8 image
    ... I'm not sure if I need to use that disk or the Solaris 8 Installation ... Using RPC Bootparams for network configuration information. ... Using finish script: diag_drv.fin ... Executing JumpStart preinstall phase... ...
    (SunManagers)
  • Re: understanding lambda
    ... All functions in the script are created when the script is parsed. ... A lambda function is created when the script is executing - and is not created unless that statement is executed. ... a new solid -- say, a cylinder, I would take two steps: ...
    (alt.php)
  • QUESTION: shared libraries
    ... how would I create a package easy-to-install for a new user? ... we could use a script to install the package. ... I have seen some scripts executing from a ... Gouvernement du Canada / Government of Canada ...
    (comp.os.linux.development.apps)
  • QUESTION: shared libraries
    ... how would I create a package easy-to-install for a new user? ... we could use a script to install the package. ... takes root privileges to do so. ... I have seen some scripts executing from a ...
    (comp.os.linux.development.system)