By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
431,900 Members | 1,078 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 431,900 IT Pros & Developers. It's quick & easy.

Zend Development and erroneous Assignment Condition bugs

P: n/a
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

Jul 17 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
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

ne**@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


Jul 17 '05 #2

P: n/a
dm*******@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, <de*****@cauce.org> is a spam trap.
Real e-mail address unavailable. 5000+ spams per month.
Jul 17 '05 #3

P: n/a
In <11**********************@z14g2000cwz.googlegroups .com>, on
02/25/2005
at 09:12 AM, dm*******@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 sp******@library.lspace.org

Jul 17 '05 #4

P: n/a
<dm*******@yahoo.com> wrote in message
news:11**********************@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().
Jul 17 '05 #5

P: n/a
"Chung Leong" <ch***********@hotmail.com> wrote in message news:<0N********************@comcast.com>...
<dm*******@yahoo.com> wrote in message
news:11**********************@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
}
Jul 17 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.