php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #33325 Type hinting and defaults of NULL
Submitted: 2005-06-13 19:17 UTC Modified: 2005-06-13 23:48 UTC
From: jacob at jacobweber dot com Assigned:
Status: Wont fix Package: Feature/Change Request
PHP Version: 5.0.4 OS: All
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: jacob at jacobweber dot com
New email:
PHP Version: OS:

 

 [2005-06-13 19:17 UTC] jacob at jacobweber dot com
Description:
------------
When using type-hinting in a function's arguments, PHP should allow a default value of NULL. Otherwise you have to manaully check the type with instanceof. This would make it more convenient, and more consistent with Java.

Reproduce code:
---------------
function f (MyClass $o = NULL) {
  echo "success";
}

f();

Expected result:
----------------
success

Actual result:
--------------
PHP compiler error.

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-06-13 23:44 UTC] iliaa@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

This is intended behaviour.
 [2005-06-13 23:48 UTC] tony2001@php.net
This was discussed before and the conclusion was not to implement it.
Please search internals archives for the discussion (this message can help probably: http://www.mail-archive.com/internals@lists.php.net/msg13629.html).
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Sat Jul 05 12:01:34 2025 UTC