Web lists-archives.com

[PHP] Difficulty with semicolon




Hello;
This is the second time I have had to deal with this issue.
It is the result of my own typing errors. But I thought it would
be worthwhile sharing the implicit problem.

You may notice the line marked '//<<<'  There is a semicolon immediately
following the closing ')'.

This is part of a function to create a directory with a default index.php file
This code would not run if the directory had not been created successfully.

What happened was that the error implied by file_put_contents returning false
was sent: EVEN though the file WAS actually created. It appears that the semi
colon caused the false value to be converted to true and the error was sent.
Or it just canceled the conditional test and the error block was run with out it.
(I didn't think it was possible). 

So, the take away is that it would be worthwhile for a syntax error to the issued
in this case. I can't think of any conditional or looping construct that would use
a semicolon at this location usefully. And lord knows that if you leave one out
where it needs to be, you hear about it.

$_indTxt = "<?php\n/* code */;\n"."?".">";
 if(file_put_contents($_tar."/index.php", $_indTxt) === false); // <<<
   {
     $_out['error'] = $_errHead." file named ".$_tarShrt."/index.php file not created";
     return $_out;
   }

Thanks for time and attention.
JK
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php