|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #43456 Class property type hints
Submitted: 2007-11-29 16:55 UTC Modified: 2019-01-25 16:10 UTC
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: kjarli at gmail dot com Assigned: nikic (profile)
Status: Closed Package: Class/Object related
PHP Version: * OS: *
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: kjarli at gmail dot com
New email:
PHP Version: OS:


 [2007-11-29 16:55 UTC] kjarli at gmail dot com
Why not adding something like this in classes:

public $array:Array;
private $bool:Bool = false;
protected $number:Number = 40;
var $string:String = 'a text';

This is like forcing a variable into a bool, array, number etc.
This should be pure for classes only.
Assigning an array value to like a :Number, will cause a notice error.

This is usefull for 
1. Debugging
2. accessing public values
3. If you are working with more than 1 person, your class won't get messed up.
4. if you use like :Number, and you insert '10', it can force it into a number.


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2015-01-09 00:58 UTC]
-Summary: forcing type of variable in class +Summary: Class property type hints -Package: Feature/Change Request +Package: Class/Object related -Operating System: +Operating System: * -PHP Version: 5.2.5 +PHP Version: *
 [2018-08-22 02:31 UTC]
An RFC about this topic has been opened:
 [2019-01-03 11:59 UTC]
-Assigned To: +Assigned To: nikic
 [2019-01-25 16:10 UTC]
-Status: Assigned +Status: Closed
 [2019-01-25 16:10 UTC]
The implementation for the aforementioned RFC has been merged, and typed properties will be available in PHP 7.4.
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Mon Aug 26 01:01:26 2019 UTC