Reputation: 3310
I have some code from a previous programmer and I'm a little confused to what it means. The if statement is:
if( !$this->report = $this->get_report()){
... do something }
I'm used to seeing the if statement with some "truthy" condition or a comparison operator.
Is this saying if $this->report is false or doesn't exist then make it = $this_.get_report()?
Upvotes: 0
Views: 122
Reputation: 43481
if( !$this->report = $this->get_report())
This line is doing two things:
$this->get_report()
to $this->report
false
Only if it does compare (loosely to false
), it runs the block do something
Example of another loose comparison:
<?php
if(!$foo = null) {
// going to process this block
}
$foo
is assigned a null
valuenull
loosely compares to false
in PHP
null == false
loose comparisonnull !== false
strict comparison!false
results in true
, so the block gets executedUpvotes: 1