php.net |  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
Votes:2
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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: kjarli at gmail dot com
New email:
PHP Version: OS:

 

 [2007-11-29 16:55 UTC] kjarli at gmail dot com
Description:
------------
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.


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2015-01-09 00:58 UTC] ajf@php.net
-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] carusogabriel@php.net
An RFC about this topic has been opened: https://wiki.php.net/rfc/typed_properties_v2
 [2019-01-03 11:59 UTC] nikic@php.net
-Assigned To: +Assigned To: nikic
 [2019-01-25 16:10 UTC] nikic@php.net
-Status: Assigned +Status: Closed
 [2019-01-25 16:10 UTC] nikic@php.net
The implementation for the aforementioned RFC has been merged, and typed properties will be available in PHP 7.4.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Dec 22 12:01:30 2024 UTC