assignment in PHP
<p>I am learning php and read this example in this <a href="http://www.php.net/manual/en/language.types.boolean.php" rel="nofollow">http://www.php.net/manual/en/language.types.boolean.php</a> tutorial,
I want to understand what occur when assigning the return value of method to a variable, why it may change?? please see my questions in the code.</p>

<pre><code>&lt;?php

public function myMethod()
{
return 'test';
}

public function myOtherMethod()
 {
 return null;
 }

if($val = $this-&gt;myMethod())
{
  // $val might be 1 instead of the expected 'test'  
                                                    ** why it may returns 1??**

}

if( ($val = $this-&gt;myMethod()) )
{
// now $val should be 'test'
}

// or to check for false
if( !($val = $this-&gt;myMethod()) )                    **what happens here????**
{
 // this will not run since $val = 'test' and equates to true
 }

// this is an easy way to assign default value only if a value is not returned:

if( !($val = $this-&gt;myOtherMethod()) )             **what happens here????**
{
$val = 'default'
}

?&gt;
</code></pre>
