Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 13 of 13
  1. #1
    Senior Coder
    Join Date
    Aug 2005
    Posts
    1,119
    Thanks
    2
    Thanked 1 Time in 1 Post

    unexpected T_IF do not know what is wrong?

    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 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.

  • #2
    teh Moderatorinator
    Join Date
    Sep 2004
    Location
    USA
    Posts
    2,472
    Thanks
    4
    Thanked 40 Times in 40 Posts
    Missing semi-colon:
    $configstat = substr(sprintf('%o', fileperms('../includes/config.inc.php')), -4);

  • #3
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,465
    Thanks
    0
    Thanked 634 Times in 624 Posts
    Why use:

    if(($configstat == 0777) == TRUE)

    when

    if($configstat == 0777)

    is shorter and faster to perform exactly the same test?
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.

  • #4
    Senior Coder
    Join Date
    Aug 2005
    Posts
    1,119
    Thanks
    2
    Thanked 1 Time in 1 Post
    because that returns true, and i need to check if it is true. Your thinking, is my original thinking, but it leads to problems.

  • #5
    Senior Coder
    Join Date
    Apr 2005
    Location
    Colorado, United States
    Posts
    1,208
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Felgall is correct. They both serve the same purpose, however if($configstat == 0777) is both shorter and faster.
    "$question = ( to() ) ? be() : ~be();"

  • #6
    Regular Coder Element's Avatar
    Join Date
    Jul 2004
    Location
    Lynnwood, Washington, US
    Posts
    855
    Thanks
    2
    Thanked 2 Times in 2 Posts
    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.

  • #7
    Senior Coder
    Join Date
    Aug 2005
    Posts
    1,119
    Thanks
    2
    Thanked 1 Time in 1 Post
    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.

  • #8
    Regular Coder Element's Avatar
    Join Date
    Jul 2004
    Location
    Lynnwood, Washington, US
    Posts
    855
    Thanks
    2
    Thanked 2 Times in 2 Posts
    Quote Originally Posted by thesavior
    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.

  • #9
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,465
    Thanks
    0
    Thanked 634 Times in 624 Posts
    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).
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.

  • #10
    Regular Coder Element's Avatar
    Join Date
    Jul 2004
    Location
    Lynnwood, Washington, US
    Posts
    855
    Thanks
    2
    Thanked 2 Times in 2 Posts
    Quote Originally Posted by felgall
    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:

    PHP Code:

    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.

  • #11
    Senior Coder
    Join Date
    Aug 2005
    Posts
    1,119
    Thanks
    2
    Thanked 1 Time in 1 Post
    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.

  • #12
    Senior Coder
    Join Date
    Aug 2003
    Location
    One step ahead of you.
    Posts
    2,815
    Thanks
    0
    Thanked 3 Times in 3 Posts
    Quote Originally Posted by felgall
    $test = $configstat == 0777;
    if ($test)
    Is it too late to add that $test is not needed and we would end up at
    Code:
    if($configstat == 0777)
    again?
    I'm not sure if this was any help, but I hope it didn't make you stupider.

    Experience is something you get just after you really need it.
    PHP Installation Guide Feedback welcome.

  • #13
    Regular Coder Element's Avatar
    Join Date
    Jul 2004
    Location
    Lynnwood, Washington, US
    Posts
    855
    Thanks
    2
    Thanked 2 Times in 2 Posts
    I sure hope so.

    Edit: That is too thesaviors post a bove yours, Marek.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •