php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #28712 NULL can't be passed to argument with class type hint.
Submitted: 2004-06-09 19:02 UTC Modified: 2004-06-10 09:01 UTC
Votes:3
Avg. Score:2.3 ± 1.9
Reproduced:3 of 3 (100.0%)
Same Version:3 (100.0%)
Same OS:1 (33.3%)
From: davojan at mail dot ru Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: PHP5-RC3 OS: FreeBSD 4.7-RELEASE
Private report: No CVE-ID: None
 [2004-06-09 19:02 UTC] davojan at mail dot ru
Description:
------------
Actually it was tested in RC3 (I don't find it in PHP version list).
It's very inconveniently, if I can't pass NULL instead of object to the function.
In the example below the default value is used, but there is a same behaviour, when I pass NULL explicitly.
I understand, that the report:
http://bugs.php.net/bug.php?id=26780&edit=2
intersects with my, but my opinion is that not accepting NULLs is an evident bug, very serious bug! And my example with the default value illustrates it very well.

Reproduce code:
---------------
<?
	class foo {};
	function bar (foo $f = NULL) { echo 'ok'; }
	bar();
?>

Expected result:
----------------
ok

Actual result:
--------------
Fatal error: Argument 1 must not be null in /usr/local/www/data-dist/ils/admin/test/null.php on line 3

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-06-09 19:19 UTC] davojan at mail dot ru
The compromise can be to add new configuration parameter, something like "allow_type_hinted_pass_null", to enable or disable this feature.
 [2004-06-10 01:34 UTC] imprestavel at gameguru dot com dot br
or just drop the type-hint
unless you use your class as if it was NULL (do nothing with it), you are going to check that argument anyway
keep it simple
maybe it doesnt make much difference, but since php team already discussed it, probably with a similar example in mind, and went this way, i think we would need to give them a much better reason to change back
 [2004-06-10 09:01 UTC] derick@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

For a reason, please read the internals@ archive of about 2 months ago.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri May 03 22:01:33 2024 UTC