Zend Development and erroneous Assignment Condition bugs

This is a discussion on Zend Development and erroneous Assignment Condition bugs within the PHP Language forums, part of the PHP Programming Forums category; I'm trying out the Zend Development Environment 4, and for the most part I like it, except for two ...


Go Back   Usenet Forums > PHP Programming Forums > PHP Language

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 02-25-2005
news@celticbear.com
 
Posts: n/a
Default 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_array($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_array($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

Reply With Quote
  #2 (permalink)  
Old 02-25-2005
dmcconkey@yahoo.com
 
Posts: n/a
Default 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_array description:

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

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

while ($row = mysql_fetch_array($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_array 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_array( $result_pass )

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

Incidentally, I don't like using the mysql_fetch_array 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:
> 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_array($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_array($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


Reply With Quote
  #3 (permalink)  
Old 02-26-2005
Jan Pieter Kunst
 
Posts: n/a
Default Re: Zend Development and erroneous Assignment Condition bugs

dmcconkey@yahoo.com wrote:
> 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.


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.
Reply With Quote
  #4 (permalink)  
Old 02-27-2005
Shmuel (Seymour J.) Metz
 
Posts: n/a
Default Re: Zend Development and erroneous Assignment Condition bugs

In <1109351522.465823.221360@z14g2000cwz.googlegroups .com>, on
02/25/2005
at 09:12 AM, dmcconkey@yahoo.com said:

>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.


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:

>However, mysql_fetch_array 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.


So assignment doesn't always evaluate to true, does it?

>The Zend bug engine should recognize such special functions.


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@library.lspace.org

Reply With Quote
  #5 (permalink)  
Old 02-28-2005
Chung Leong
 
Posts: n/a
Default Re: Zend Development and erroneous Assignment Condition bugs

<dmcconkey@yahoo.com> wrote in message
news:1109351522.465823.221360@z14g2000cwz.googlegr oups.com...
> 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.


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


Reply With Quote
  #6 (permalink)  
Old 03-15-2005
Norm 2782
 
Posts: n/a
Default Re: Zend Development and erroneous Assignment Condition bugs

"Chung Leong" <chernyshevsky@hotmail.com> wrote in message news:<0NKdnRFzuIOh-r7fRVn-uw@comcast.com>...
> <dmcconkey@yahoo.com> wrote in message
> news:1109351522.465823.221360@z14g2000cwz.googlegr oups.com...
> > 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.

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


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
}
Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 10:57 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0