Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Assignment in condition

Status
Not open for further replies.

PCHomepage

Programmer
Feb 24, 2009
609
US
On several pages, I am getting an error referring to Assignment in condition in:

Code:
while ( list ( $key, $value ) = each ( $table ) ) { . . .

I understand the error but I am not sure of the correct syntax to use. Can anyone help? Thanks.

Don
 
The syntax looks o.k, and does not generate an error on my side.

What does your $table array look like?





----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Web & Tech
 
Actually it works fine as it is but apparently using list ( $key, $value ) = each ( $table ) is not correct and is marked with warnings by Zend Studio. This was one example of many and in most cases I could easily see what was needed but not on this one.

For example, this:

Code:
 while ( $info = mysql_fetch_row ( $this->Query_ID ) ) {

wanted to be this:

Code:
$info = mysql_fetch_row ( $this->Query_ID );
while ( $info ) {
 
In that case I would say Zend Studio is a little to strict for its own good. Because in your example the way it wants it to be does not perform the required task, which is to loop through the returned rows. As long as there are rows to return the while loop keeps going.

With your second method, the row retrieval is limited to a single row, unless you are issuing the $info=mysql_fetch_row() call inside the while loop also.

This adds 2 rows of unnecessary code.

You can disable it though as it is the Semantic checking in Zend studio.




----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Web & Tech
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top