Paul,

the warning that John refers to does occur - whether you see it depends on the error reporting level, PHP will create the array for you if you have not already initialized it but a warning will be generated in such cases. - errors that may not display on one machine might be visible on another due to differences in the error reporting level.

error reporting level is set in the php.ini file (it can also be set in your script see http://nl2.php.net/ini_set), you probably have a line in your php.ini that looks like:

error_reporting = E_ALL & ~E_WARNING & ~E_NOTICE

which means: log all errors except warning level and notice level errors
I recommend you try to set the error reporting level to:

error_reporting = E_ALL

in this way all errors are logged (and possibly displayed) - if you can write bug/error free code with error reporting set to E_ALL then you will have made a good start towards more professional/better coding practices.

there is another php.ini line:

display_errors = On

this line determines if errors are output to the browser window. for web development this should be definitely on. (productions server often have it Off for speed and 'niceness' reasons - i.e. not many users are interested in seeing PHP errors, for whatever reason!)

---

as a rule of thumb it is better to initialize variable before you use them.

e.g. $pictures = array();

otherwise, in your case, if no files are present in the directory (or none have a 'jpg' extension) referencing the $pictures array the while loop will cause another error.

---
Side Note:
for beginners often RTFM only leads to more confusion because the contents of many technical manuals often assume that the reader has knowledge which a beginner does not yet have. I don't feel that this is very much the case of the PHP manual - my feeling is that is very accessible. I recommend taking the time to read all of it - the parts you don't yet understand often become clear with continued reading. The time invested in reading the manual is quickly regained!



Paul Furman wrote:


OK thanks again for helping through the stumbling blocks... I'm rolling again now.


John W. Holmes wrote:



Just make sure $pictures is defined as an array before you try to push a
value onto it (even using the method you have now), otherwise you'll get a
warning.


It seems to be working fine this way without defining it as an array but I guess other languages would not accept that approach.


while ($file = readdir($dh)){ if (strstr ($file, '.jpg')){ $pictures[] = $file; }


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



Reply via email to