title: Can PHP's (float) casting ever return a non-float value?
body: <p>I'm debugging some code and the previous developer wrote:</p>
  
  <pre class="lang-php prettyprint-override"><code>if (!is_float((float)$value)) {
    throw new \Exception();
  }
  </code></pre>
  
  <p>In the below table <code>R</code> is the result of converting the <code>VALUE</code> with the specified <code>TYPE</code> to <code>(float)</code>. <code>x</code> means different values are possible here.</p>
  
  <pre><code>R     TYPE VALUE
  -     ---- -----
  0          null
  0     bool false
  1     bool true
  x      int x
  x    float x
  0   string 'invalid'
  x   string 'x'
  0    array []
  1    array [x]
  1   object x (raises a notice)
  x resource handle (unintuitive)
  </code></pre>
  
  <p>I haven't been able to find any value that can't be converted to <code>(float)</code>. Is it at all possible for the above <code>\Exception</code> to be thrown?</p>
  
  <p><a href="https://www.php.net/manual/en/language.types.float.php#language.types.float.casting" rel="nofollow noreferrer">The PHP documentation</a> says:</p>
  
  <blockquote>
    <h2>Converting to float</h2>
    
    <p>For information on converting strings to float, see String conversion to numbers. For values of other types, <strong>the conversion is performed by converting the value to integer first and then to float</strong>. See Converting to integer for more information. As of PHP 5, a notice is thrown if an object is converted to float.</p>
  </blockquote>
  
  <p>(emphasis mine)</p>
  
  <p>So as far as I can tell, the above <code>\Exception</code> is unreachable code. Is this correct or did the other developer know something I don't?</p>