php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #67312 type hinting exception handling
Submitted: 2014-05-20 19:02 UTC Modified: 2014-05-23 02:48 UTC
From: bhasker dot t dot an at gmail dot com Assigned:
Status: Wont fix Package: *General Issues
PHP Version: 5.4.28 OS: windows
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: bhasker dot t dot an at gmail dot com
New email:
PHP Version: OS:

 

 [2014-05-20 19:02 UTC] bhasker dot t dot an at gmail dot com
Description:
------------
class a {
    protected function method_a(someClass $obj)
    {
      /// some code
    }
}

$a = new a();
$a->method_a('hellow');
//this throws an error


Test script:
---------------
class a {
    protected function method_a(someClass $obj)
    {
      /// some code
    }
}

$a = new a();
$a->method_a('hellow');
//this throws an error

Expected result:
----------------
could be grate if there is possiblity to write like

class a {
    protected function method_a(someClass $obj) throws someException
    {
      /// some code
    }
}
try {
   $a = new a();
   $a->method_a('hellow');
}catch (someException $e){
   //catch exception
}

Actual result:
--------------
throwing fatal error

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2014-05-23 02:48 UTC] aharvey@php.net
-Status: Open +Status: Wont fix
 [2014-05-23 02:48 UTC] aharvey@php.net
For reasons of consistency, this is unlikely to be changed unless all PHP errors are converted to exceptions, which is a much bigger undertaking. This would require an RFC and would almost certainly be something that would need to be in a new major version.

I'm closing the request, as I think it's unlikely we'd add syntax to throw a specific exception in this case.
 [2014-05-24 14:52 UTC] anon at anon dot anon
The 'throws' keyword is flawed and annoying enough in Java. I don't want it added to PHP too. If you want methods to be more self-documenting, you can put the exceptions they throw in a /** comment */.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Tue Apr 22 04:01:26 2025 UTC