Forum Moderators: coopster

Message Too Old, No Replies

Call to member non object, help please

         

askeli

12:16 pm on Nov 7, 2004 (gmt 0)

10+ Year Member



I am using a script that lists the contents of a directory etc, this works fine on one server (uk) but on another server (us) i get:
Fatal error: Call to a member function on a non-object in .... line 44

Line44 =

while($file=$d->read()){

The relevant code is:

/* If you're including this script from a function, you'll need
to make $SCRIPT_FILENAME a global variable. */

if (!$SCRIPT_FILENAME)
global $SCRIPT_FILENAME;

// We'll have to loop through all the files in the current directory
$d = dir(dirname($SCRIPT_FILENAME));
while($file=$d->read()){

any ideas suggestions appreciated

many Thanks

[edited by: ergophobe at 10:50 pm (utc) on Nov. 7, 2004]

ergophobe

4:33 pm on Nov 7, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Askeli,

Basically, what this means, is that $d is not an object. Since dir() should create a pseudo-object, I would guess that means that the directory read failed.

Is there a chance that the path in $SCRIPT_FILENAME is not valid?

Note also that the manual [php.net] does the condition checking in the while loop as follows

while (false!== ($entry = $d->read()))

for reasons explained there

Tom

askeli

1:49 pm on Nov 8, 2004 (gmt 0)

10+ Year Member



many thanks, ill have a go later and let you know.