if(is_array($_POST)) always = TRUE - why?

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

    #1

    if(is_array($_POST)) always = TRUE - why?


    Folks,

    I test if my PHP should process form data by checking if $_POST is an
    array - However I always find its condition proves true - Why or
    alternatvily, what other method can one use to check for this sort of
    situation?

    <?
    if(is_array($_P OST))
    { die("<h1>here</h1>"); }
    ?>

    I have tried isset() too and this also returns TRUE when it should be
    false... must I always test with a count($_POST)== 0?

    ideas/solutions/anyone?

    most appreciated - via the newsgroup
    thanks
    randelld


  • Andy Hassall

    #2
    Re: if(is_array($_P OST)) always = TRUE - why?

    On Thu, 30 Oct 2003 23:00:29 GMT, "Randell D."
    <you.can.email. me.at.randelld@ yahoo.com> wrote:
    [color=blue]
    >I test if my PHP should process form data by checking if $_POST is an
    >array - However I always find its condition proves true - Why or
    >alternatvily , what other method can one use to check for this sort of
    >situation?[/color]

    $_POST _is_ always an array.
    [color=blue]
    ><?
    > if(is_array($_P OST))
    > { die("<h1>here</h1>"); }
    >?>
    >
    >I have tried isset() too and this also returns TRUE when it should be
    >false...[/color]

    No, it should always be true. $_POST, $_GET, etc. are all superglobal arrays,
    which are always defined.
    [color=blue]
    >must I always test with a count($_POST)== 0?[/color]

    Yes.

    --
    Andy Hassall (andy@andyh.co. uk) icq(5747695) (http://www.andyh.co.uk)
    Space: disk usage analysis tool (http://www.andyhsoftware.co.uk/space)

    Comment

    • Daniel Tryba

      #3
      Re: if(is_array($_P OST)) always = TRUE - why?

      Randell D. <you.can.email. me.at.randelld@ yahoo.com> wrote:[color=blue]
      > I have tried isset() too and this also returns TRUE when it should be
      > false... must I always test with a count($_POST)== 0?[/color]

      Check for a value that should be in the post (like the submit button or
      other mandatory keys):

      if(array_key_ex ists('foo',$_PO ST))
      {
      ...
      }

      --

      Daniel Tryba

      Comment

      • R. Rajesh Jeba Anbiah

        #4
        Re: if(is_array($_P OST)) always = TRUE - why?

        "Randell D." <you.can.email. me.at.randelld@ yahoo.com> wrote in message news:<hKgob.227 810$pl3.442@pd7 tw3no>...[color=blue]
        > Folks,
        >
        > I test if my PHP should process form data by checking if $_POST is an
        > array - However I always find its condition proves true - Why or
        > alternatvily, what other method can one use to check for this sort of
        > situation?
        >
        > <?
        > if(is_array($_P OST))
        > { die("<h1>here</h1>"); }
        > ?>
        >
        > I have tried isset() too and this also returns TRUE when it should be
        > false... must I always test with a count($_POST)== 0?
        >
        > ideas/solutions/anyone?[/color]

        1. if ($_POST) //if form posted??

        2. if (isset($_POST['foo'])) //if form posted by clicking "foo"
        button. Can be used if more than one submit button is present or more
        than one form is present.
        [color=blue]
        > most appreciated - via the newsgroup[/color]

        Is there anyone to reply via email :-/

        ---
        "If there is a God, he must be a sadist!"
        Email: rrjanbiah-at-Y!com

        Comment

        • Alan Little

          #5
          Re: if(is_array($_P OST)) always = TRUE - why?

          Carved in mystic runes upon the very living rock, the last words of Randell
          D. of comp.lang.php make plain:
          [color=blue]
          > I test if my PHP should process form data by checking if $_POST is an
          > array - However I always find its condition proves true - Why or
          > alternatvily, what other method can one use to check for this sort of
          > situation?[/color]

          if ($_SERVER['REQUEST_METHOD '] == "POST")

          --
          Alan Little
          Phorm PHP Form Processor

          Comment

          Working...