php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #63264 Type hinting in list()
Submitted: 2012-10-11 19:58 UTC Modified: 2021-08-25 15:43 UTC
Votes:2
Avg. Score:4.0 ± 1.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: michaelrfairhurst at gmail dot com Assigned: cmb (profile)
Status: Wont fix Package: Arrays related
PHP Version: 5.3.17 OS: CentOs 6
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: michaelrfairhurst at gmail dot com
New email:
PHP Version: OS:

 

 [2012-10-11 19:58 UTC] michaelrfairhurst at gmail dot com
Description:
------------
Since list is a language construct, it would be great if it had type hinting.

list(ContractPrice $price, Adjustment $adj) = $deps;

truth be told I got this whim from PHPUnit, where I like having type hinting on 
my @dependent tests -- example is based on that.


Test script:
---------------
/**
 * @depends testReturns_ContractPrice
 */
function testReturnsArray(ContractPrice $price) {
    $adjustment = new Adjustment;
    $this->assertEquals('stuff', $price->stuff($adjustment));

    return array($price, $adjustment);
}


/**
 *@depends testReturns_Array
 */
function testTypeHintingLists(array $deps) {
    list(ContractPrice $price, Adjustment $adjustment) = $deps;
}


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2021-08-25 15:43 UTC] cmb@php.net
-Status: Open +Status: Wont fix -Assigned To: +Assigned To: cmb
 [2021-08-25 15:43 UTC] cmb@php.net
This doesn't make much sense on its own; I mean other local
variables should be typeable as well, if we do that.  Anyhow, this
would require the RFC process[1], and given that there has been no
feedback on this ticket so far, I'm closing as WONTFIX.

For now you can use a static analyzer.

[1] <https://wiki.php.net/rfc/howto>
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Dec 22 01:01:30 2024 UTC