Very Weird Behavior

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

    Very Weird Behavior

    I started with the following code in an included file:

    $CompanyBlock =
    "$Company (Booth#: $Booth)\n".
    "$Address\n ".
    "$City, $State $PostalCode\n".
    "$Website\n ".
    "$Contact1, $Title1\n".
    "Tel: $Phone\n".
    "Fax: $Fax\n".
    "Email: $Email1\n".
    "Products/Services: $ProductService \n".
    "Objectives : ";

    I wanted to make some of the items conditional, but in so doing, I forgot
    to change some of the . to ; and ended up with:

    $CompanyBlock = $Company;
    if ($Booth) $CompanyBlock.= " (Booth#: $Booth)";

    $CompanyBlock.=
    "\n".
    "$Address\n ".
    "$City, $State $PostalCode\n";

    if ($Website) $CompanyBlock.= "$Website\n ";
    if ($Contact1) $CompanyBlock.= "$Contact1" ;
    if ($Title1) $CompanyBlock.= ", $Title1"; $CompanyBlock.= "\n";
    if ($Phone) $CompanyBlock.= "Tel: $Phone\n".
    if ($Fax) $CompanyBlock.= "Fax: $Fax\n".
    if ($Email1) $CompanyBlock.= "Email: $Email1\n".
    if ($ProductServic e)
    $CompanyBlock.= "Products/Services: $ProductService \n".

    $CompanyBlock.= "Objectives : ";

    The result? The file returns with no execution, not even of code before
    the problem, and with no error message, not so much as a notice. It took
    me a good while to narrow it down and spot the problem (there's quite a
    bit of code before this in the file). I knew the file was being called,
    but even an echo statement at the very beginning produced no output. The
    execution of the main script was not affected.

    I thought this might save someone else a bit of time if they happen to
    have the same problem.

    --
    Alan Little
    Phorm PHP Form Processor

  • Erwin Moller

    #2
    Re: Very Weird Behavior

    Alan Little wrote:
    [color=blue]
    > I started with the following code in an included file:
    >
    > $CompanyBlock =
    > "$Company (Booth#: $Booth)\n".
    > "$Address\n ".
    > "$City, $State $PostalCode\n".
    > "$Website\n ".
    > "$Contact1, $Title1\n".
    > "Tel: $Phone\n".
    > "Fax: $Fax\n".
    > "Email: $Email1\n".
    > "Products/Services: $ProductService \n".
    > "Objectives : ";
    >
    > I wanted to make some of the items conditional, but in so doing, I forgot
    > to change some of the . to ; and ended up with:
    >
    > $CompanyBlock = $Company;
    > if ($Booth) $CompanyBlock.= " (Booth#: $Booth)";
    >
    > $CompanyBlock.=
    > "\n".
    > "$Address\n ".
    > "$City, $State $PostalCode\n";
    >
    > if ($Website) $CompanyBlock.= "$Website\n ";
    > if ($Contact1) $CompanyBlock.= "$Contact1" ;
    > if ($Title1) $CompanyBlock.= ", $Title1"; $CompanyBlock.= "\n";
    > if ($Phone) $CompanyBlock.= "Tel: $Phone\n".
    > if ($Fax) $CompanyBlock.= "Fax: $Fax\n".
    > if ($Email1) $CompanyBlock.= "Email: $Email1\n".
    > if ($ProductServic e)
    > $CompanyBlock.= "Products/Services: $ProductService \n".
    >
    > $CompanyBlock.= "Objectives : ";
    >
    > The result? The file returns with no execution, not even of code before
    > the problem, and with no error message, not so much as a notice. It took
    > me a good while to narrow it down and spot the problem (there's quite a
    > bit of code before this in the file). I knew the file was being called,
    > but even an echo statement at the very beginning produced no output. The
    > execution of the main script was not affected.
    >
    > I thought this might save someone else a bit of time if they happen to
    > have the same problem.
    >[/color]


    Sorry, I think you code in a weird way..
    What do you expect from if($varname) ?
    Does your script rely on registerglobals = on?

    Of course I cannot see the rest of your setup, so maybe I am talking bull.
    ;-)

    Regards,
    Erwin Moller


    Comment

    • Alan Little

      #3
      Re: Very Weird Behavior

      Carved in mystic runes upon the very living rock, the last words of
      Erwin Moller of comp.lang.php make plain:
      [color=blue][color=green]
      >> The result? The file returns with no execution, not even of code
      >> before the problem, and with no error message, not so much as a
      >> notice. It took me a good while to narrow it down and spot the
      >> problem (there's quite a bit of code before this in the file). I knew
      >> the file was being called, but even an echo statement at the very
      >> beginning produced no output. The execution of the main script was
      >> not affected.
      >>
      >> I thought this might save someone else a bit of time if they happen
      >> to have the same problem.[/color]
      >
      > Sorry, I think you code in a weird way..[/color]

      Perhaps, but it has no bearing on the issue. That is, if I used isset()
      instead, perhaps it wouldn't tickle this particular bug, but it is in
      fact a bug. Which reminds me, I should report it.
      [color=blue]
      > What do you expect from if($varname) ?[/color]

      I expect PHP to tell me if it has a problem. While if ($var) may not be
      ideal coding practice, it is legal.

      --
      Alan Little
      Phorm PHP Form Processor

      Comment

      • Sean

        #4
        Re: Very Weird Behavior

        If you checked the php error log it would have printed out something
        like:

        [27-Nov-2005 16:04:12] PHP Parse error: syntax error, unexpected T_IF
        in etc......

        i.e.

        if ($Phone) $CompanyBlock.= "Tel: $Phone\n".
        if ($Fax) $CompanyBlock.= "Fax: $Fax\n".
        if ($Email1) $CompanyBlock.= "Email: $Email1\n".

        Take this section of code, your concatenating IF statements like
        strings so of course it's not going to work.

        You should start by going to http://www.php.net/manual/en/

        Comment

        • Ian B

          #5
          Re: Very Weird Behavior


          Alan Little wrote:[color=blue]
          >
          > Perhaps, but it has no bearing on the issue. That is, if I used isset()
          > instead, perhaps it wouldn't tickle this particular bug, but it is in
          > fact a bug. Which reminds me, I should report it.[/color]

          It's not a bug, it's illegal code. You can't terminate a line with a
          dot, and you can't concatenate an if statement into a string. It
          produces a parse error and stops execution. If you don't get an error
          message it is because of your settings. It is still an error, though.
          [color=blue]
          >[color=green]
          > > What do you expect from if($varname) ?[/color]
          >
          > I expect PHP to tell me if it has a problem. While if ($var) may not be
          > ideal coding practice, it is legal.
          >[/color]

          Legal, yes. Useful in this situation, no. What you are saying in effect
          is "if the website name can be converted to a non-zero number, then..."

          I don't mean to give offence, but you should consider coding like other
          people do, at least until you understand the consequences of not doing
          so.

          Ian

          Comment

          • Alan Little

            #6
            Re: Very Weird Behavior

            Carved in mystic runes upon the very living rock, the last words of Ian
            B of comp.lang.php make plain:
            [color=blue]
            > Alan Little wrote:[color=green]
            >>
            >> Perhaps, but it has no bearing on the issue. That is, if I used
            >> isset() instead, perhaps it wouldn't tickle this particular bug, but
            >> it is in fact a bug. Which reminds me, I should report it.[/color]
            >
            > It's not a bug, it's illegal code. You can't terminate a line with a
            > dot,[/color]

            Sure you can, unless you mean you can't terminate a statement with a
            dot. Nothing wrong with terminating a line with a dot, if your intention
            to to concatenate whatever's on the next line.
            [color=blue]
            > and you can't concatenate an if statement into a string.[/color]

            Of course. As mentioned originally, I inserted the if's, and forgot the
            change the appropriate dots to semicolons.
            [color=blue]
            > It produces a parse error and stops execution.[/color]

            It does neither. No error, and execution resumes in the main code (this
            was in an included file).
            [color=blue]
            > If you don't get an error message it is because of your settings.[/color]

            error_reporting = E_ALL
            [color=blue][color=green][color=darkred]
            >> > What do you expect from if($varname) ?[/color]
            >>
            >> I expect PHP to tell me if it has a problem. While if ($var) may not
            >> be ideal coding practice, it is legal.[/color]
            >
            > Legal, yes. Useful in this situation, no. What you are saying in
            > effect is "if the website name can be converted to a non-zero number,
            > then..."[/color]

            I understand. And it is useful in this situation. It basically is a
            shortcut of if(strlen(trim( $Website)))
            [color=blue]
            > I don't mean to give offence,[/color]

            None taken.
            [color=blue]
            > you should consider coding like other people do, at least until
            > you understand the consequences of not doing so.[/color]

            Well, I do understand exactly what the code is doing, but to be honest I
            don't believe I've heard all the arguments against using it; I just know
            there are some.

            --
            Alan Little
            Phorm PHP Form Processor

            Comment

            • Alan Little

              #7
              Re: Very Weird Behavior

              Carved in mystic runes upon the very living rock, the last words of Sean
              of comp.lang.php make plain:
              [color=blue]
              > If you checked the php error log it would have printed out something
              > like:
              >
              > [27-Nov-2005 16:04:12] PHP Parse error: syntax error, unexpected T_IF
              > in etc......[/color]

              Assuming error logging is on, which it isn't in this case, but error
              reporting is, and there was no error.
              [color=blue]
              > if ($Phone) $CompanyBlock.= "Tel: $Phone\n".
              > if ($Fax) $CompanyBlock.= "Fax: $Fax\n".
              > if ($Email1) $CompanyBlock.= "Email: $Email1\n".
              >
              > Take this section of code, your concatenating IF statements like
              > strings so of course it's not going to work.[/color]

              I understand that. As stated in my original post, the code was initially
              a single block of concatenation; I added the if's, and forgot to change
              the appropriate dots to semicolons.
              [color=blue]
              > You should start by going to http://www.php.net/manual/en/[/color]

              Gosh, a whole new world of enlightenment I hadn't seen before!

              --
              Alan Little
              Phorm PHP Form Processor

              Comment

              • Sean

                #8
                Re: Very Weird Behavior

                Its display_errors in the php.ini which needs to be turned on that
                displays errors as part of the output.

                Comment

                • Alan Little

                  #9
                  Re: Very Weird Behavior

                  Carved in mystic runes upon the very living rock, the last words of Sean of
                  comp.lang.php make plain:
                  [color=blue]
                  > Its display_errors in the php.ini which needs to be turned on that
                  > displays errors as part of the output.[/color]

                  Ah yes, that's turned off. It's still odd that it would continue execution
                  of the main code though, with a parse error in the included file. Even with
                  display_errors off, that is not the normal behavior.

                  Oh well.

                  --
                  Alan Little
                  Phorm PHP Form Processor

                  Comment

                  Working...