When can I use "OR"

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Smitro

    When can I use "OR"

    Hi,

    How come in some statements I can use:

    If (something) or DIE();

    but other times it won't work (returns an error) unless I take out the
    OR.

    Is there any documentation on this anywhere?

  • Bent Stigsen

    #2
    Re: When can I use "OR&quo t;

    Smitro wrote:[color=blue]
    > Hi,
    >
    > How come in some statements I can use:
    >
    > If (something) or DIE();[/color]

    "or" needs two operands, so above would not not be syntactically
    correct. Perhaps you meant expressions like:

    if (something or die()) somefunc();

    $x = somefunc() or die();
    [color=blue]
    > but other times it won't work (returns an error) unless I take out the
    > OR.[/color]

    Can you give a concrete example.
    I can't think of anything that would make "or" give an error. As far
    as I know, any expression can be casted to a boolean, so it should
    check out ok.
    [color=blue]
    > Is there any documentation on this anywhere?[/color]

    Probably not. It is not a feature of PHP as such, but rather a
    "misuse" of the way PHP internally evaluates logical expressions. PHP
    will stop the evaluation of a logical expression, if a continued
    evaluation will not change the result.
    For instance, if evaluating (true or somefunc()), somefunc will not be
    called since its value does not change the result. Same would be the
    case for (false and somefunc()).

    /Bent

    Comment

    • Cylindric

      #3
      Re: When can I use "OR&quo t;


      Smitro wrote:[color=blue]
      > Hi,
      >
      > How come in some statements I can use:
      >
      > If (something) or DIE();
      >
      > but other times it won't work (returns an error) unless I take out the
      > OR.
      >
      > Is there any documentation on this anywhere?[/color]

      Think of it from a conversational point of view:

      PHP: "If (something) or DIE();"
      ENG: "If MyName=Fred Or Then DoSomething" makes no sense

      PHP: "If (something or somethingelse) Then Die();"
      ENG: "If MyName=Fred Or MyAge=92 Then DoSomething" makes sense

      PHP: "If (something) then DIE();"
      ENG: "If MyName=Fred Then DoSomething"

      Comment

      • Smitro

        #4
        Re: When can I use "OR&quo t;

        Cylindric wrote:[color=blue]
        > Smitro wrote:
        >[color=green]
        >>Hi,
        >>
        >>How come in some statements I can use:
        >>
        >>If (something) or DIE();
        >>
        >>but other times it won't work (returns an error) unless I take out the
        >>OR.
        >>
        >>Is there any documentation on this anywhere?[/color]
        >
        >
        > Think of it from a conversational point of view:
        >
        > PHP: "If (something) or DIE();"
        > ENG: "If MyName=Fred Or Then DoSomething" makes no sense
        >
        > PHP: "If (something or somethingelse) Then Die();"
        > ENG: "If MyName=Fred Or MyAge=92 Then DoSomething" makes sense
        >
        > PHP: "If (something) then DIE();"
        > ENG: "If MyName=Fred Then DoSomething"
        >[/color]

        yep, got a point, I was trying to revese and if
        statment, but then my other brain kicked in and
        said, just stick some more brackets around it.

        eg.
        If ((something) and (something else)) or Die();

        is now...

        If (!((something) and (something else))) die();

        Comment

        • Adam i Agnieszka Gasiorowski FNORD

          #5
          Just Stick Some More Brackets Around It Was: Re: When can I use "OR&quo t;

          On 2005-09-16 09:30:58 +0000, Smitro <nospam@myh0use .c0m> said:
          [color=blue]
          > [...] just stick some more brackets around it.
          >
          > eg.
          > If ((something) and (something else)) or Die();
          >
          > is now...
          >
          > If (!((something) and (something else))) die();[/color]


          This starts to look dangerously close to LISP
          code! ;-} (Beware `(the (Jabberwock))). ..

          -- 
          Seks, seksiæ, seksolatki...<u ri: news:pl.soc.sek s.moderowana > <~|{ A.A }|
          Love, give me a reason to be beautiful! Miles and miles of perfect skin,
           I said I fit so perfect in! I'm fading like a rose...Give me a reason!!!
          https://hyperreal.info | https://kanaba.info |=> "Go¶ciu! Szanuj Zieleñ!"

          Comment

          Working...