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 7 of 7
  1. #1
    Senior Coder crmpicco's Avatar
    Join Date
    Jan 2005
    Location
    Mauchline, Scotland
    Posts
    1,097
    Thanks
    15
    Thanked 1 Time in 1 Post

    plus sign in IF statement

    Hi,

    Does anyone know what the "+" is used for in this IF statement? I have found it in a script, but have no idea what it is for.

    PHP Code:
    if (+$default_stadium_id) {
      
    // ... code in here ...

    Thanks,
    Picco

  • #2
    New Coder
    Join Date
    Jan 2010
    Location
    The Netherlands
    Posts
    53
    Thanks
    10
    Thanked 0 Times in 0 Posts
    Its an operator.
    I don't know enough of PHP to know what it does here, but maybe this helps:
    http://www.tizag.com/phpT/operators.php

    Edit: Preincrement, when something is executed before
    Last edited by Pcfr43k; 01-27-2010 at 01:20 PM. Reason: more info

  • #3
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    It does nothing. It will not increment a variable, flip a negative bit, or assign the variable to another or a new value. It also will not throw an error.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 
    Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)

  • #4
    New Coder
    Join Date
    Jul 2008
    Location
    India
    Posts
    39
    Thanks
    0
    Thanked 2 Times in 2 Posts

    Thumbs up It does not do anything nor flips negative value to positive.

    <?
    $a = -1;
    $b = 1;

    if (+$a>0 ){
    echo "Print it!";
    }
    ?>
    Output of above code is nothing.

    It does not do anything nor flips negative value to positive.Why dont you try to change values of the variable here? And look for whats expected there.

    Check for operator overloading if its a class member.

  • #5
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    PHP doesn't support operator overloading with the exception of index control using the ArrayAccess interface.

    Oh, I should mention though that php does support one unary: -$var. That will flip it. Never used it though, so I have no idea what it actually does. The documentation is ambiguous as to if the 'opposite' is just flipping the sign bit, or if the 'opposite' is flipping all bits, and I can't test this atm. I'd suspect just the sign bit, since we have the bit not (~).
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 
    Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)

  • #6
    Senior Coder crmpicco's Avatar
    Join Date
    Jan 2005
    Location
    Mauchline, Scotland
    Posts
    1,097
    Thanks
    15
    Thanked 1 Time in 1 Post
    Strange one I guess, i'll have a look into "bit flipping" as I guess that is something that could raise it's head in a Zend Exam.

    But I presume from the comments here that the "+" in the if condition was simply to prevent the code from ever running, without actually removing it from the script or commenting it out.

    Cheers,
    Picco

  • #7
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    No, it will still execute normally. The + literally does nothing, it doesn't empty a variable or alter it in any way.
    If you run this:
    PHP Code:
    $t = -1;
    if (+
    $t 0)
    {
        print 
    $t;

    This will still execute and print -1. On the other hand, the - does have an effect:
    PHP Code:
    $t 1;
    if (-
    $t 0)
    {
        
    // Directly flipped the sign:
        
    print $t;

    This will execute and print 1.
    Also:
    PHP Code:
    $t = -1;
    if (-
    $t 0)
    {
        print 
    $t;

    Will not execute. It evaluates the negative value of $t which is negative already, and therefore can not be less than 0. Therefore, this will not print.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 
    Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)


  •  

    Posting Permissions

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