|  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
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
 [2008-01-04 04:51 UTC] sam at sambarrow dot com
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
- Resources (specified by "resource")
- Objects (matches any object, specified by "object")


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2008-01-04 15:09 UTC]
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]
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]
-Status: Suspended +Status: Closed -Package: Feature/Change Request +Package: *General Issues -Assigned To: +Assigned To: levim
 [2018-04-08 18:05 UTC]
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-2019 The PHP Group
All rights reserved.
Last updated: Sun May 19 12:01:26 2019 UTC