Can't use function return value in write context--huh?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • kurt.krueckeberg@gmail.com

    Can't use function return value in write context--huh?

    Can someone explain why this line
    $bool = isset($_POST['email']) && !empty(trim($_P OST['email']));
    causes the error message "Can't use function return value in write
    context". trim() returns a string. I test if it is empty. So what is
    wrong with that?
  • Olaf Schinkel

    #2
    Re: Can't use function return value in write context--huh?

    kurt.krueckeber g@gmail.com schrieb:
    Can someone explain why this line
    $bool = isset($_POST['email']) && !empty(trim($_P OST['email']));
    causes the error message "Can't use function return value in write
    context". trim() returns a string. I test if it is empty. So what is
    wrong with that?
    The functions empty() *only* tests Variables.
    All other wil cause an error.

    Comment

    • The Hajj

      #3
      Re: Can't use function return value in write context--huh?

      On Jul 25, 1:39 pm, kurt.krueckeb.. .@gmail.com wrote:
      Can someone explain why this line
      $bool = isset($_POST['email']) && !empty(trim($_P OST['email']));
      causes the error message "Can't use function return value in write
      context". trim() returns a string. I test if it is empty. So what is
      wrong with that?
      not that speed matters but && $_POST['email'] != '' is how I would do
      it.

      As mentioned above and to quote from php.net "Note: empty() only
      checks variables as anything else will result in a parse error. In
      other words, the following will not work: empty(trim($nam e)). "

      What I said above is faster than

      $email = trim($_POST['email'];

      if (... && !empty($email)

      Comment

      • larry@portcommodore.com

        #4
        Re: Can't use function return value in write context--huh?

        On Jul 25, 10:39 am, kurt.krueckeb.. .@gmail.com wrote:
        Can someone explain why this line
        $bool = isset($_POST['email']) && !empty(trim($_P OST['email']));
        causes the error message "Can't use function return value in write
        context". trim() returns a string. I test if it is empty. So what is
        wrong with that?)
        Your function would fail if 'email' isn't set.

        try this:

        $bool = !empty( ( isset( $_POST['eamil'] ) ? trim( $_POST['email'] ) :
        '' ) );

        Comment

        • Jerry Stuckle

          #5
          Re: Can't use function return value in write context--huh?

          larry@portcommo dore.com wrote:
          On Jul 25, 10:39 am, kurt.krueckeb.. .@gmail.com wrote:
          >Can someone explain why this line
          >$bool = isset($_POST['email']) && !empty(trim($_P OST['email']));
          >causes the error message "Can't use function return value in write
          >context". trim() returns a string. I test if it is empty. So what is
          >wrong with that?)
          >
          Your function would fail if 'email' isn't set.
          >
          try this:
          >
          $bool = !empty( ( isset( $_POST['eamil'] ) ? trim( $_POST['email'] ) :
          '' ) );
          >
          Incorrect. That's what isset() tests. If $_POST['email'] is not set,
          the rest of the expression is never evaluated.

          The others had it correct - empty() only works on variables, not the
          results of an expression.

          --
          =============== ===
          Remove the "x" from my email address
          Jerry Stuckle
          JDS Computer Training Corp.
          jstucklex@attgl obal.net
          =============== ===

          Comment

          • kkruecke

            #6
            Re: Can't use function return value in write context--huh?

            Incorrect. That's what isset() tests. If $_POST['email'] is not set,
            the rest of the expression is never evaluated.
            >
            The others had it correct - empty() only works on variables, not the
            results of an expression.
            Thanks for mentioning that "If $_POST['email'] is not set, the rest of
            the expression is never evaluated." That is why I did
            isset( $_POST['eamil']) first.

            Comment

            • Jerry Stuckle

              #7
              Re: Can't use function return value in write context--huh?

              kkruecke wrote:
              >Incorrect. That's what isset() tests. If $_POST['email'] is not set,
              >the rest of the expression is never evaluated.
              >>
              >The others had it correct - empty() only works on variables, not the
              >results of an expression.
              >
              Thanks for mentioning that "If $_POST['email'] is not set, the rest of
              the expression is never evaluated." That is why I did
              isset( $_POST['eamil']) first.
              >
              Yep, and that is the correct way to do it.

              --
              =============== ===
              Remove the "x" from my email address
              Jerry Stuckle
              JDS Computer Training Corp.
              jstucklex@attgl obal.net
              =============== ===

              Comment

              Working...