mercredi 6 septembre 2017

Assignment instead of comparison in if statement [duplicate]

This question already has an answer here:

I just came across an idea and do not know a clear answer for that.

What actually happens when I use assignment operator instead of operator of equality. So for example like this:

<?php
    include( 'database.php' );   // this file includes db connection in variable $mysql

    $result = $mysql->query( /*some query*/ );
    while( $row = $result->fetch_assoc() )
        // do something
?>

I already know that the while loop at line 5 runs till fetch_assoc() does not return NULL. It implicates me that PHP standard defines this thing as C11 standard:

An assignment expression has the value of the left operand after the assignment

Is this really true or PHP standard defines that other way?

Aucun commentaire:

Enregistrer un commentaire