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
Have you experienced this issue?
Rate the importance of this bug to you:

 [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: Fri Mar 29 10:01:28 2024 UTC