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
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: 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

Pull Requests

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: Fri Dec 27 02:01:29 2024 UTC