Zend Development and erroneous Assignment Condition bugs

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • news@celticbear.com

    Zend Development and erroneous Assignment Condition bugs

    I'm trying out the Zend Development Environment 4, and for the most
    part I like it, except for two things.

    It seems to think certain lines that are perfectly valid are bugs. Like
    this:

    while ($row_pass = mysql_fetch_arr ay($result_pass )) {

    It gives an "Assignment in Condition" error whenever it encounters a
    line like that, which is a lot. It gives a little explanation box
    giving it a "Category: Bug" and goes on to explain how variables should
    go on the right-hand side of an equality statement, and double equals
    should be used, like this:

    if ($x == "1") {

    Yeah, for logicals, but when assigning an array to a mySQL querey, I've
    always used
    while ($row_pass = mysql_fetch_arr ay($result_pass )) {
    and it works perfectly.

    Is there a way to get Zend to recognize this, ignore this, or am I
    doing something wrong in that line of code I've used for years without
    problem?

    Thanks!

    Oh, the other problem I'm having involves it not being able to connect
    to any mySQL database except as root, even if another mySQL account has
    full privileges, etc. But I'll deal with this later I guess.

    Thanks,
    Liam

  • dmcconkey@yahoo.com

    #2
    Re: Zend Development and erroneous Assignment Condition bugs

    Liam,

    I'm not familiar with the Zend IDE. I'm downloading now for a test
    drive. However, I tried looking at your problem from a code
    perspective.

    I pulled this example from php.net's mysql_fetch_arr ay description:

    <?php
    mysql_connect(" localhost", "mysql_user ", "mysql_password ") or
    die("Could not connect: " . mysql_error());
    mysql_select_db ("mydb");

    $result = mysql_query("SE LECT id, name FROM mytable");

    while ($row = mysql_fetch_arr ay($result, MYSQL_NUM)) {
    printf("ID: %s Name: %s", $row[0], $row[1]);
    }

    They use the optional second argument, but otherwise your code is
    identical.

    Normal while iterations are conditional, evaluating the statement at
    the beginning of each iteration. Using assignment in a while condition
    check _should_ always evaluate to true, looping forever. Thus, tripping
    up the Zend bug engine.

    However, mysql_fetch_arr ay function uses an internal data pointer to
    travel the array incrementally. When it reaches the end of the array,
    it causes the while to evaluate to false, breaking out of the loop. If
    you were to use an equality evaluator (==), it would always evaluate as
    false, as $row_pass will never equal mysql_fetch_arr ay( $result_pass )

    The Zend bug engine should recognize such special functions. It
    apparently does not.

    Incidentally, I don't like using the mysql_fetch_arr ay function because
    of this. It hides what's going on. To me, a programmer should be able
    to look at code and immediately recognize the logical progression.
    Nowhere in this code can we see the data pointer advancing through the
    array. It's confusing to someone not intimately familiar with the
    standard library.

    Because of this--even though it takes a little more time--I always use
    for ( $i = 0; $i < count( $my_array ); $i++ ) type iteration with SQL
    results. It's easier to read and immediately understand.

    Sorry I couldn't help with the Zend problem, though.

    Good luck,
    -Dan

    news@celticbear .com wrote:[color=blue]
    > I'm trying out the Zend Development Environment 4, and for the most
    > part I like it, except for two things.
    >
    > It seems to think certain lines that are perfectly valid are bugs.[/color]
    Like[color=blue]
    > this:
    >
    > while ($row_pass = mysql_fetch_arr ay($result_pass )) {
    >
    > It gives an "Assignment in Condition" error whenever it encounters a
    > line like that, which is a lot. It gives a little explanation box
    > giving it a "Category: Bug" and goes on to explain how variables[/color]
    should[color=blue]
    > go on the right-hand side of an equality statement, and double equals
    > should be used, like this:
    >
    > if ($x == "1") {
    >
    > Yeah, for logicals, but when assigning an array to a mySQL querey,[/color]
    I've[color=blue]
    > always used
    > while ($row_pass = mysql_fetch_arr ay($result_pass )) {
    > and it works perfectly.
    >
    > Is there a way to get Zend to recognize this, ignore this, or am I
    > doing something wrong in that line of code I've used for years[/color]
    without[color=blue]
    > problem?
    >
    > Thanks!
    >
    > Oh, the other problem I'm having involves it not being able to[/color]
    connect[color=blue]
    > to any mySQL database except as root, even if another mySQL account[/color]
    has[color=blue]
    > full privileges, etc. But I'll deal with this later I guess.
    >
    > Thanks,
    > Liam[/color]

    Comment

    • Jan Pieter Kunst

      #3
      Re: Zend Development and erroneous Assignment Condition bugs

      dmcconkey@yahoo .com wrote:[color=blue]
      > Because of this--even though it takes a little more time--I always use
      > for ( $i = 0; $i < count( $my_array ); $i++ ) type iteration with SQL
      > results. It's easier to read and immediately understand.[/color]

      A tip from the PHP Cookbook: do it like this:

      for ($i = 0, $size = count($my_array ); $i < $size; $i++)

      so you call the count() function only once instead of in every iteration.

      JP

      --
      Sorry, <devnull@cauce. org> is a spam trap.
      Real e-mail address unavailable. 5000+ spams per month.

      Comment

      • Shmuel (Seymour J.) Metz

        #4
        Re: Zend Development and erroneous Assignment Condition bugs

        In <1109351522.465 823.221360@z14g 2000cwz.googleg roups.com>, on
        02/25/2005
        at 09:12 AM, dmcconkey@yahoo .com said:
        [color=blue]
        >Normal while iterations are conditional, evaluating the statement at
        >the beginning of each iteration. Using assignment in a while
        >condition check _should_ always evaluate to true, looping forever.[/color]

        No. What is the value of an assignment? In particular, what is the
        value of an assignment when the RHS is zero or null? The answer is
        implicit in your subsequent paragraph:
        [color=blue]
        >However, mysql_fetch_arr ay function uses an internal data pointer to
        >travel the array incrementally. When it reaches the end of the
        >array, it causes the while to evaluate to false, breaking out of the
        >loop.[/color]

        So assignment doesn't always evaluate to true, does it?
        [color=blue]
        >The Zend bug engine should recognize such special functions.[/color]

        There's nothing special about them. It's normal behavior for a
        function to return null pointers as a sign of failure or termination.

        --
        Shmuel (Seymour J.) Metz, SysProg and JOAT <http://patriot.net/~shmuel>

        Unsolicited bulk E-mail subject to legal action. I reserve the
        right to publicly post or ridicule any abusive E-mail. Reply to
        domain Patriot dot net user shmuel+news to contact me. Do not
        reply to spamtrap@librar y.lspace.org

        Comment

        • Chung Leong

          #5
          Re: Zend Development and erroneous Assignment Condition bugs

          <dmcconkey@yaho o.com> wrote in message
          news:1109351522 .465823.221360@ z14g2000cwz.goo glegroups.com.. .[color=blue]
          > Normal while iterations are conditional, evaluating the statement at
          > the beginning of each iteration. Using assignment in a while condition
          > check _should_ always evaluate to true, looping forever. Thus, tripping
          > up the Zend bug engine.[/color]

          The result from the assignment operator is the lvalue. There's nothing
          special about using it inside while().


          Comment

          • Norm 2782

            #6
            Re: Zend Development and erroneous Assignment Condition bugs

            "Chung Leong" <chernyshevsky@ hotmail.com> wrote in message news:<0NKdnRFzu IOh-r7fRVn-uw@comcast.com> ...[color=blue]
            > <dmcconkey@yaho o.com> wrote in message
            > news:1109351522 .465823.221360@ z14g2000cwz.goo glegroups.com.. .[color=green]
            > > Normal while iterations are conditional, evaluating the statement at
            > > the beginning of each iteration. Using assignment in a while condition
            > > check _should_ always evaluate to true, looping forever. Thus, tripping
            > > up the Zend bug engine.[/color]
            >
            > The result from the assignment operator is the lvalue. There's nothing
            > special about using it inside while().[/color]

            I got this some where of a forum. Works fine and Zend Studio doesn't
            give anymore errors:

            while(($row = $result->fetch_assoc( )) != false) {
            //Do stuff
            }

            Comment

            Working...