-- logart <[email protected]> wrote
(on Saturday, 06 February 2010, 08:52 AM -0800):
> I am just playing with Zend Studio and Zend Framework and have noticed a lot
> of warning messages in my framework code. Here is an example:
> 
> Zend->Amf->Parse->Amf3->Deserializer.php line 326.
> 
> Warning: Assignment in condition
> if ($loader = Zend_Amf_Parse_TypeLoader::loadType($className)) {
> 
> Isn't that assigning a value to the test instead of testing it for a value?
> Unless there is some weird internal thing going on that requires this type
> of assignment?

This type of condition is doing two things:

 * First, it's assigning the left side to the return value of the right
   side.
 * Second, it's then testing if the left side is now a value that does
   not evaluate to false.

Written longhand, it would be as follows:

    $loader = Zend_Amf_Parse_TypeLoader::loadType($className);
    if ($loader) {
        // ...
    }

As written, it's simply a shortcut to reduce code verbosity. Studio is
warning about it to ensure that you didn't actually mean to do an
equality test (which would use ==).

However, it's perfectly valid usage, and it's found in a variety of
locations in ZF.

-- 
Matthew Weier O'Phinney
Project Lead            | [email protected]
Zend Framework          | http://framework.zend.com/
PGP key: http://framework.zend.com/zf-matthew-pgp-key.asc

Reply via email to