Bug #74150 [Nab]: Passing null value and default restriction

From: Date: Wed, 22 Feb 2017 17:04:34 +0000
Subject: Bug #74150 [Nab]: Passing null value and default restriction
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-207511@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=74150&edit=1 ID: 74150 User updated by: aaatoja at o2 dot pl Reported by: aaatoja at o2 dot pl Summary: Passing null value and default restriction Status: Not a bug Type: Bug Package: Class/Object related Operating System: Debian PHP Version: 7.1.2 Block user comment: N Private report: N New Comment: Ok, but starting with 7.1 it doesn't make sense: "Type declarations allow functions to require that parameters are of a certain type at call time. If the given value is of the incorrect type, then an error is generated" a(string $test=null) // incorrect type, should throw error a(string $test='test') // valid type, ok a(?string $test=null) // valid type, ok a(?string $test='test') // valid type, ok Previous Comments: ------------------------------------------------------------------------ [2017-02-22 16:53:27] requinix@php.net Thank you for taking the time to write to us, but this is not a bug. Please double-check the documentation available at http://www.php.net/manual/ and the instructions on how to report a bug at http://bugs.php.net/how-to-report.php http://php.net/manual/en/functions.arguments.php#functions.arguments.type-declaration > The declaration can be made to accept NULL values if the default value of the > parameter is set to NULL. ------------------------------------------------------------------------ [2017-02-22 16:12:56] aaatoja at o2 dot pl Description: ------------ Shouldn't code below throw TypeError exception: Argument 1 passed to test::a() must be of the type string, null given? Nullable type is not allowed here. This should work only with a(?string $x=null) Test script: --------------- class test { public function a(string $x=null) { echo 'a'; } } $x = new test; $x->a(null); Expected result: ---------------- TypeError exception Actual result: -------------- Null value as an argument is accepted. ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=74150&edit=1

« previous php.bugs (#207511) next »