Andi Gutmans wrote:As no good syntax has been found for the less common case of allowing NULL's, I think the best solution for now is not to allow null in the regular type hint syntax, and have people who want to allow NULL's not use type hints at all (in any case, they need to manually check their parameter so they'll do one more manual check).
We can then wait and see how much feedback we receive on this issue after 5.0 and if necessary, revisit this. In any case, if the default is not to allow null pretty much any solution we will come up with will keep BC.
Why not allow NULL if null is specified as the default value? i.e. if the parameter is optional? This change sounds like you can no longer use typehints for optional parameters. I have tons of code that looks like this:
public function save(Connection $con = null) { if ($con === null) { $con = .....; } ... }
I like that typehints will force $con to be of type Connection if not NULL. I like this & feel it would be very unfortunate (and obviously very breaking) for this to go away.
Moving to the semantics that type hints don't allow NULL is not consistent with allowing NULL default values. In this case, you will have to not use type hints. As I mentioned, it's best to go this way for 5.0 and see responses and see how applications are being written during 5.0 adoption.
Andi
-- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php