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
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:
MUST BE VALID
Solve the problem:
33 - 12 = ?
Subscribe to this entry?

 
 [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: Sun Apr 28 21:01:29 2024 UTC