Re: [Linux dev] Undefined variables

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 9/8/06, Alf Stockton <alf@xxxxxxxxxxxxxx> wrote:
In this little script:-

<?php
session_start();
//read folder
$folder=opendir(".");
while ($file = readdir($folder))
$names[count($names)] = $file;  // <----- Line 8

Obviously $names won't be defined in the initial state the first time this line
is hit, thus count($names) would/should be undefined...

closedir($folder);
//sort file names in array
sort($names);
//remove any non-images from array
$tempvar = $i = 0;

These "shortcircuit" assignments aren't the best of things to do...

for ($i=0;$names[$i];$i++) {    // <----- Line 14

Remember the undefined case up there, there just might not be a
index 0, be rather an index "undefined" ....

Don't we just *love* these interpreted languages and their "funnies" :)

I keep getting:-

[Fri Sep 08 17:04:57 2006] [error] [client 127.0.0.1] PHP Notice:
Undefined variable: names in C:\\Program Files\\Apache Software
Foundation\\Apache2.2\\htdocs\\events\\adverts\\ridtoo.php on line 8,
referer: http://localhost/events/rotate.shtml
[Fri Sep 08 17:04:57 2006] [error] [client 127.0.0.1] PHP Notice:
Undefined offset:  13 in C:\\Program Files\\Apache Software
Foundation\\Apache2.2\\htdocs\\events\\adverts\\ridtoo.php on line 14,
referer: http://localhost/events/rotate.shtml

Please tell me what evil I have committed to cause this?

--
Regards,
Alf Stockton            www.stockton.co.za

Lay on, MacDuff, and curs'd be him who first cries, "Hold, enough!".
                -- Shakespeare
My email disclaimer is available at www.stockton.co.za/disclaimer.html

---
To unsubscribe: send the line "unsubscribe dev" in the subject of a
mail to dev-request@xxxxxxxxxxxxx Problems: dev-admins@xxxxxxxxxxxx
Archives at http://www.linux.org.za/Lists-Archives/




--
Groete in Jesus Christus, ons enigste Verlosser en Saligmaker
Greetings in Jesus Christ, our only Saviour and Salvation.
Hendrik Visage

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


[Index of Archives]     [PHP Home]     [PHP Users]     [PHP Database Programming]     [PHP Install]     [Kernel Newbies]     [Yosemite Forum]     [PHP Books]

  Powered by Linux