php.net |  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.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
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
Description:
------------
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;


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2020-01-03 15:26 UTC] geekcom@php.net
-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] geekcom@php.net
-Operating System: ubuntu +Operating System: -PHP Version: 7.2.26 +PHP Version: Next Major Version
 [2020-01-03 15:32 UTC] geekcom@php.net
-Summary: PHP parse_url incorrect +Summary: Nullable type casting -PHP Version: Next Major Version +PHP Version: 8
 [2020-01-03 15:41 UTC] geekcom@php.net
-Assigned To: +Assigned To: geekcom
 [2020-01-03 15:49 UTC] geekcom@php.net
Hi Karolis,

Send an e-mail to internals@lists.php.net 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 http://php.net/mailing-lists.php. (Reminder: always "bottom post" your replies. Never “top post”.)

For detailed RFC Process instructions please see:

https://wiki.php.net/rfc/howto
 [2020-01-03 15:50 UTC] nikic@php.net
-Package: PHP Language Specification +Package: *General Issues
 [2020-01-03 16:23 UTC] rowan dot collins at gmail dot com
Hi,

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.

[1] https://externals.io/message/102997
[2] https://externals.io/message/105122
[3] https://wiki.php.net/rfc/nullable-casting

Regards,
Rowan Tommins
[IMSoP]
 [2020-01-03 18:21 UTC] requinix@php.net
-Status: Assigned +Status: Suspended
 
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Fri Nov 27 23:01:24 2020 UTC