php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #43745 Scalar type hinting
Submitted: 2008-01-04 04:51 UTC Modified: 2018-04-08 18:05 UTC
Votes:5
Avg. Score:4.6 ± 0.8
Reproduced:4 of 4 (100.0%)
Same Version:2 (50.0%)
Same OS:2 (50.0%)
From: sam at sambarrow dot com Assigned: levim (profile)
Status: Closed Package: *General Issues
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 !
Your email address:
MUST BE VALID
Solve the problem:
30 + 28 = ?
Subscribe to this entry?

 
 [2008-01-04 04:51 UTC] sam at sambarrow dot com
Description:
------------
Requesting support for scalar type hinting. I have a fully working patch written, I have been using it myself with no problems for a couple of months.

Full specs:
Type hinting patch allows for 8 new type hints, in addition to array and class type hinting.

- Integers (specified by "int", "integer", or "long")
- Floats (specified by "float", "double", or "real")
- Numbers (matches integers and floats, specified by "num" or "number")
- Strings (specified by "string")
- Booleans (specified by "bool" or "boolean")
- Scalars (matches strings, booleans, and numbers; specified by
"scalar")
- Resources (specified by "resource")
- Objects (matches any object, specified by "object")



Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-01-04 15:09 UTC] helly@php.net
We will not implement scalar type hints.
Check the archives on the exact why.
For pure hinting you can use pecl/SPL_Types which will act like Java autoboxing.
 [2008-01-04 15:46 UTC] pajoye@php.net
won't fix > suspended.


There is a discussion about such features and no, it is not yet done.
 [2010-01-25 20:09 UTC] alll-developers at php dot world
Why won't these type hintings be implemented?
For me and every serious PHP Developer in the world it would be so cool to have that feature
 [2018-04-08 18:05 UTC] levim@php.net
-Status: Suspended +Status: Closed -Package: Feature/Change Request +Package: *General Issues -Assigned To: +Assigned To: levim
 [2018-04-08 18:05 UTC] levim@php.net
Nearly all of this has been implemented as of PHP 7.2. We don't allow the duplicate names for scalar types. We also don't have "resource" or "num"/"number". I'm sure we have bugs for those somewhere; when I find them I'll link to them.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Mar 28 20:01:28 2024 UTC