php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #46865 Typed variables and class members
Submitted: 2008-12-14 20:25 UTC Modified: 2016-12-30 15:13 UTC
Votes:5
Avg. Score:4.6 ± 0.5
Reproduced:5 of 5 (100.0%)
Same Version:3 (60.0%)
Same OS:3 (60.0%)
From: zyss at mail dot zp dot ua Assigned:
Status: Suspended Package: *General Issues
PHP Version: 5.2.8 OS: Linux, Windows
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 — but make sure to vote on the bug!
Your email address:
MUST BE VALID
Solve the problem:
48 + 31 = ?
Subscribe to this entry?

 
 [2008-12-14 20:25 UTC] zyss at mail dot zp dot ua
Description:
------------
Currently it is possible to specify class types for function arguments. It would be very helpful to also add an ability to set types for function return values, variables (local and global) and especially for class members. In general - to improve types checking when it is required by programmer, it will help to eliminate hidden errors that are sometimes hard to find now. For example:

  class Foo {
    private Foo $next;

    function Foo getNext() {
      return $this->next;
    }
  }

  class Bar {
    private Foo $foo;

    function doo(Foo $prevFoo) {
      Foo $newFoo = $prevFoo->getNext();
      $this->foo = $newFoo;
    }
  }



Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2016-12-30 15:13 UTC] cmb@php.net
-Status: Open +Status: Suspended -Package: Feature/Change Request +Package: *General Issues
 [2016-12-30 15:13 UTC] cmb@php.net
FTR: return type declarations are available as of PHP 7.0.0. An
RFC to add optional property type declarations[1] has been
declined not long ago.

Anyhow, any such feature would require the RFC process[2], so I'm
suspending this request.

[1] <https://wiki.php.net/rfc/typed-properties>
[2] <https://wiki.php.net/rfc/howto>
 
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Thu Dec 03 01:01:23 2020 UTC