php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #38128 Add scalar-type hinting
Submitted: 2006-07-18 05:55 UTC Modified: 2006-07-18 06:45 UTC
From: obluda dot x at seznam dot cz Assigned:
Status: Wont fix Package: Feature/Change Request
PHP Version: * 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: obluda dot x at seznam dot cz
New email:
PHP Version: OS:

 

 [2006-07-18 05:55 UTC] obluda dot x at seznam dot cz
Description:
------------
Currently, only object and array arguments of a function can be hinted. However, if you can't hint non-class/non-array argument, you have to leave argument unhinted, which allows passing of class/array besides of scalar types.

I propose adding new type-hinting keyword 'scalar', which matches complement to currently possible hints. Think also about 'resource' hint.

Reproduce code:
---------------
<?php
        function show ( scalar $string ) {
                echo $string;
        }
        show("hello\n");
        show(new stdClass());
?>

Expected result:
----------------
hello
Error...


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-07-18 06:45 UTC] helly@php.net
Ressource and Object typehinting are the only types we probably add in some future. But we discussed and disagreed to the others already. There is no need and it actually would contradict the php way where all variables are casted as needed.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Apr 20 16:01:29 2024 UTC