|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #80208 Scalar pseudo-type (like Iterable)
Submitted: 2020-10-09 11:15 UTC Modified: 2020-10-09 12:01 UTC
From: divinity76 at gmail dot com Assigned:
Status: Suspended Package: Unknown/Other Function
PHP Version: Next Minor Version OS:
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please — but make sure to vote on the bug!
Your email address:
Solve the problem:
8 - 6 = ?
Subscribe to this entry?

 [2020-10-09 11:15 UTC] divinity76 at gmail dot com
i suggest a scalar pseudo-type, much like Iterable,

today if one wants to accept scalar arguments, one has to write something like:

function f($sc){
    if(!is_string($sc) && !is_int($sc) && !is_float($sc) && !is_bool($sc)){
        throw new \InvalidArgumentException('argument #1 ($sc) must be a scalar type');
class C{
    public $sc;
    function set_sc($sc){
        if(!is_string($sc) && !is_int($sc) && !is_float($sc) && !is_bool($sc)){
            throw new \InvalidArgumentException('argument #1 ($sc) must be a scalar type');
        $this->sc = $sc;

luckily it gets easier in PHP8,

function f(string|int|float|bool $sc){

class C{
    public string|int|float|bool $sc

even so, if there was a Scalar pseudo-type, i would use it.

Test script:
function fun(Scalar $sc){

Expected result:

Actual result:
Fatal error: Uncaught TypeError: fun(): Argument #1 ($sc) must be of type Scalar, int given, called in /in/PDjNq on line 6 and defined in /in/PDjNq:3
Stack trace:
#0 /in/PDjNq(6): fun(1)
#1 {main}
  thrown in /in/PDjNq on line 3

Process exited with code 255.


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2020-10-09 11:26 UTC] divinity76 at gmail dot com
... i should have googled more, apparently it's already an "RFC under discussion",
 [2020-10-09 11:36 UTC]
I have a fairly up-to-date PR exactly for this which I don't plan to pursue: Please feel free to start an RFC by using this implementation if you would like this functionality in PHP.
 [2020-10-09 12:01 UTC]
-Status: Open +Status: Suspended
 [2020-10-09 12:01 UTC]
Yes, that would need an RFC.  Feel free to pursue.  For the time
being, I'm suspending this ticket.
PHP Copyright © 2001-2022 The PHP Group
All rights reserved.
Last updated: Sun Jul 03 22:05:46 2022 UTC