thesavior 01-01-2006, 03:08 AM im getting an error:
Parse error: parse error, unexpected T_IF in /raid5/home/eli/public_html/test/tms/install/install1.php on line 3
in this code:
<?php
$configstat = substr(sprintf('%o', fileperms('../includes/config.inc.php')), -4)
if(($configstat == 0777) == TRUE)
{
echo "<span style=\"color:green;\"> ../includes/config.inc.php is 777</span>";
} else {
echo "<span style=\"color:red;\">Please chmod ../includes/config.inc.php to 0777.</span>";
echo $configstat; // etc...
}
?>
and i am not fimiliar with the error, to decide what is wrong with it.
Brandoe85 01-01-2006, 03:16 AM Missing semi-colon:
$configstat = substr(sprintf('%o', fileperms('../includes/config.inc.php')), -4);
felgall 01-01-2006, 09:22 PM Why use:
if(($configstat == 0777) == TRUE)
when
if($configstat == 0777)
is shorter and faster to perform exactly the same test?
thesavior 01-01-2006, 09:24 PM because that returns true, and i need to check if it is true. Your thinking, is my original thinking, but it leads to problems.
Velox Letum 01-01-2006, 09:47 PM Felgall is correct. They both serve the same purpose, however if($configstat == 0777) is both shorter and faster.
Element 01-01-2006, 09:56 PM Or to explain something more, your way is basically checking if its true twice...
var == something returns true or false, where a s (var == something) == true is checking if its true twice.so basically it results in:
(TRUE) == TRUE which isn't nessessary.
thesavior 01-01-2006, 10:01 PM i think it is necessary because it is saying:
if (blah blah blah) == true
there just so happens to be another equals inside the parens.
If i don't do it that way, it returns true, and doesn't continue. So im saying that if it is true, then do this.
Element 01-01-2006, 10:06 PM i think it is necessary because it is saying:
if (blah blah blah) == true
there just so happens to be another equals inside the parens.
If i don't do it that way, it returns true, and doesn't continue. So im saying that if it is true, then do this.
no... you have it all wrong, the var == whatever DOES return true, its the same thing as (var == whatever) == true, but with that your doing it twice.
now if its something like (var = somefunction()) == true then its checking if the var, with the function didn't have any problems and is true, though once again, var == somefunction() does the same thing.
felgall 01-02-2006, 09:23 PM You could also code it as:
$test = $configstat == 0777;
if ($test)
The first statement evaluates whether the content of $configstatus is 0777 and if it is it sets $test to true otherwise it sets it ti false. The if statement is then simply testing a boolean variable that is either true or false to start with. (Not that you would code it this way for such a simple test but it demonstrated better how if statements actually work).
Element 01-02-2006, 09:28 PM You could also code it as:
$test = $configstat == 0777;
if ($test)
The first statement evaluates whether the content of $configstatus is 0777 and if it is it sets $test to true otherwise it sets it ti false. The if statement is then simply testing a boolean variable that is either true or false to start with. (Not that you would code it this way for such a simple test but it demonstrated better how if statements actually work).
This is the only time you should use your example, TheSavior.
For example:
function a_test($a) [
if($a == "a") {
return true;
} else {
return "The string did not contain 'a'";
}
}
if(($a = a_test("a")) == true) {
See how that works? Becuase if that function does return false, the cocndition won't recongize it as false.
thesavior 01-02-2006, 09:33 PM ok, thanks guys for being persistant. I talked with my dad, and he explained it to me in a way i understood.
Its all cleared up. :thumbsup:
marek_mar 01-02-2006, 09:44 PM $test = $configstat == 0777;
if ($test)
Is it too late to add that $test is not needed and we would end up at
if($configstat == 0777)
again?
Element 01-02-2006, 09:44 PM I sure hope so.
That is too thesaviors post a bove yours, Marek.
|
|