|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #79061 Nullable type casting
Submitted: 2020-01-03 14:08 UTC Modified: 2020-01-03 18:21 UTC
From: karolis dot bartkus at gmail dot com Assigned: geekcom (profile)
Status: Suspended Package: *General Issues
PHP Version: 8 OS:
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: karolis dot bartkus at gmail dot com
New email:
PHP Version: OS:


 [2020-01-03 14:08 UTC] karolis dot bartkus at gmail dot com
Currently the type casts allowed are: (int), (bool), (string), etc. It would be very convenient to have their nullable counterparts, i.e.: (?int), (?bool), (?string), etc.

Generally speaking the idea is to be able to do this:

$nullable_int = (?int) $nullable_string;

which would be an equivalent of this:

$nullable_int = is_null($nullable_string) ? null : (int) $nullable_string;


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2020-01-03 15:26 UTC]
-Summary: Nullable type casting +Summary: PHP parse_url incorrect -Operating System: +Operating System: ubuntu -PHP Version: Next Major Version +PHP Version: 7.2.26
 [2020-01-03 15:29 UTC]
-Operating System: ubuntu +Operating System: -PHP Version: 7.2.26 +PHP Version: Next Major Version
 [2020-01-03 15:32 UTC]
-Summary: PHP parse_url incorrect +Summary: Nullable type casting -PHP Version: Next Major Version +PHP Version: 8
 [2020-01-03 15:41 UTC]
-Assigned To: +Assigned To: geekcom
 [2020-01-03 15:49 UTC]
Hi Karolis,

Send an e-mail to to measure reaction to your intended proposal. State who would implement the feature, or whether the proposal is only a “concept”. Proceed with an RFC if feedback is not negative or if a detailed RFC will clarify the proposal. Mail list subscription is at (Reminder: always "bottom post" your replies. Never “top post”.)

For detailed RFC Process instructions please see:
 [2020-01-03 15:50 UTC]
-Package: PHP Language Specification +Package: *General Issues
 [2020-01-03 16:23 UTC] rowan dot collins at gmail dot com

The good news is, you're not the only person who wants this, or the first to suggest it. There was a mailing list thread about it 18 months ago [1] followed up by an RFC last April. [2][3]

The bad news is that there hasn't been much movement since then. The best thing to do is to read through those discussions, and maybe catch up with David and Guilliam who wrote the RFC, then post to the list to restart the discussion.


Rowan Tommins
 [2020-01-03 18:21 UTC]
-Status: Assigned +Status: Suspended
PHP Copyright © 2001-2022 The PHP Group
All rights reserved.
Last updated: Thu Dec 08 23:05:53 2022 UTC