Greg-
Hey, thanks.
Yea I suppose I am relatively new to PHP, been working with for about
a year and a half now, so sometimes there are gaps in my knowledge,
like this one. I'm fairly good at different debugging techniques, but
I get this error when I run the script from the manual which is why
I'm so confused by it.
T_ECHO is "echo". there's no "echo" anywhere near to line 6 - are
you sure that
D:\Inetpub\wwwroot\imagesexotic\Fall04\admin\check_set.php is the
file you posted to the php-general list?
No, I must be confusing everybody like nuts. The actual first two
lines of my LOCAL copy is
$root_dir = "/Users/jason/Sites/";
$folder_on_server = "";
NOT the one I had posted-- that was from my server copy. Actually the
error message I get when I run it locally is
Parse error: parse error, unexpected T_ECHO in
/Users/jason/Sites/images_exotic/REDESIGN2 FALL
04/admin/check_set_local.php on line 8
It comes out "T_PRINT" when I changes the "echo" to "print" -- which
is more like line 4.
I was only testing it on two servers in the off chance that it was a
versioning and/or windows ISS/apache problem -- but it did not appear
to be either.
The LOCAL script I am working with is as follows:
/* This is the correct way to loop over the directory. */
while (false !== ($file = readdir($handle))) {
echo "$file\n";
}
closedir($handle);
}
?>
Do you see the same parse error (T_ECHO) as described above? I think
the problem has to do with how I've used opendir() maybe-- but I
guess I'm asking for help because the manual seems to have incomplete
or inaccurate information I was wondering if anyone else had seen
this before.
Thanks again for your help
-Jason-
What I would look for first is check every line - make sure it
concludes with a ;
Also, don't start out by trying the same script on two servers. The
script is simple enough, you should get it working in a closed
environment first, and then try it elsewhere. This should cut down
on the WTF factor quite a bit :)
General debugging rules:
1) on any parse error make sure every line near the line number ends with ;
2) make sure that when you type if (blah) { you type } before you
fill in the details. The same goes for every control structure
3) don't use if/while/for/foreach without {} and you'll save trouble
down the line
4) familiarize yourself with the list of tokens - it will help a lot
in understanding what the parser is telling you.
http://us4.php.net/manual/en/tokens.php
Other than that, I also find tricky parse error bugs by deleting
lines, then adding them back in one by one until the parse error
returns.
The most useful debugging tool I've found is Zend IDE. You can get
a free personal license that will disable some of the niftier
features, but you will get the on-the-fly php validation which is
REALLY useful. The bar along the right will have little red lines at
every single parse error. It's brilliant. Plus you can step
through the scripts, which is unmeasurably useful for learning the
language.
Greg