php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #78695 [ Feature req ] Typehints `uint`, `ufloat`, `+', 'resource+' and so on
Submitted: 2019-10-19 10:49 UTC Modified: 2019-10-19 12:02 UTC
From: 6562680 at gmail dot com Assigned:
Status: Suspended Package: *General Issues
PHP Version: 7.3.10 OS: Win10
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: 6562680 at gmail dot com
New email:
PHP Version: OS:

 

 [2019-10-19 10:49 UTC] 6562680 at gmail dot com
Description:
------------
[ FEATURE REQUEST ]
[ NOT A BUG ]

uint - unsigned int (0,1,2,3)
ufloat - unsigned float

resource (replace to opened OR closed resource)

stack (array w/ordered ("default") int keys 0,1,2,3)
list (array w/non-ordered int keys 1,4,3,0)
assoc (array w/both int/string keys but fatal if only int/only string keys)
dict (array w/string keys)

+ - non-empty
resource+ (opened resource)
int+ (1,2,3... but fatal if 0)
float+ (0.01, 0.02 but fatal if 0.0)
string+ (at least one letter or fatal)
array+ (at least one item or fatal)

would be great to but not so required
string[] // list(!) of strings
Object[] // list(!) of objects

and i know that will be implemented in 7.4 - co-return 'string|array', 'OneInterface|TwoInterface'

Test script:
---------------
function hello(? int $limit)
{
  // damn i need this every time
  $limit = max(0, $limit);
  if (0 === $limit) throw \InvalidArgumentException('Error');
  
  // yes, i can: $limit = max(1, $limit);
 // and somewhere i could expect fatal error if 0 is going from another function, but this function wont throw and will work like 1 passed
}

Expected result:
----------------
Reduce count of if/elses + exceptions required when you writing simple scripts (usually required by Saas flow)

Actual result:
--------------
tonns of "if/else"
making properties to separate objects to "true OOP"

and then projects with 1500 files... instead of 100.

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2019-10-19 12:02 UTC] cmb@php.net
-Status: Open +Status: Suspended
 [2019-10-19 12:02 UTC] cmb@php.net
This feature requires discussion on the internals mailing list,
and likely the RFC process[1].  Please start the discussion there;
for the time being I'm suspending this ticket.

[1] <https://wiki.php.net/rfc/howto>
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Dec 22 01:01:30 2024 UTC