Skip to content

Instantly share code, notes, and snippets.

@FLamparski
Created December 17, 2015 11:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save FLamparski/17ba80f9fa9d51cb62ee to your computer and use it in GitHub Desktop.
Save FLamparski/17ba80f9fa9d51cb62ee to your computer and use it in GitHub Desktop.
PHP is weird
>>> function coerc2($optional = null) { printf("Optional is set? %b, Is coercable to true? %b\n", isset($optional), (bool) $optional); }
=> null
>>> coerc2()
Optional is set? 0, Is coercable to true? 0
=> null
>>> coerc2(1)
Optional is set? 1, Is coercable to true? 1
=> null
>>> coerc2(2)
Optional is set? 1, Is coercable to true? 1
=> null
>>> coerc2(null)
Optional is set? 0, Is coercable to true? 0
=> null
>>> coerc2(false)
Optional is set? 1, Is coercable to true? 0
=> null
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment