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
Have you experienced this issue?
Rate the importance of this bug to you:

 [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

Add a Patch

Pull Requests

Add a Pull Request

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-2024 The PHP Group
All rights reserved.
Last updated: Wed Jul 03 09:01:29 2024 UTC