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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
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-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 18 00:01:28 2024 UTC