Skip to content

Instantly share code, notes, and snippets.

@pinepain
Last active August 29, 2015 14:08
Show Gist options
  • Save pinepain/9a7755e8ce0d11082047 to your computer and use it in GitHub Desktop.
Save pinepain/9a7755e8ce0d11082047 to your computer and use it in GitHub Desktop.
<?php
// http://php.net/manual/en/language.oop5.typehinting.php says that type-hinted PHP parameter
// that has no default value set to null can't be null. But are you sure?
// First, register error handler which do nothing and return nothing (this is important!)
set_error_handler(function () {});
class SomeClass {}
function test(SomeClass $instance) {var_dump($instance);}
// NOTE: E_RECOVERABLE_ERROR (4096) occurs here
test(null);
// But what is this?! We have NULL in output! Are you surprised?
@pinepain
Copy link
Author

Thanks all, I have a clue what's wrong with this code. This gist just shows weird behavior I met during debugging strange NULL value for typehinted argument.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment