php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #60053 Allow throwing of strings and things
Submitted: 2011-10-13 13:32 UTC Modified: 2015-08-27 20:26 UTC
From: anon at anon dot anon Assigned:
Status: Wont fix Package: Class/Object related
PHP Version: Irrelevant 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.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: anon at anon dot anon
New email:
PHP Version: OS:

 

 [2011-10-13 13:32 UTC] anon at anon dot anon
Description:
------------
Here's my suggestion: when throwing something that's not an Exception, use it as the message of a new Exception (instead of dying). I.e.,

throw $x;

where !($x instanceof Exception)

would be interpreted as:

throw new Exception($x);

Then I could do this:

throw "I can't be arsed to type new Exception() everywhere";

>inb4 one person looks at and rejects this for some bureaucratic reason and it's never considered again.
>I mean, er, have a nice day.


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2011-10-13 13:35 UTC] anon at anon dot anon
I'd like to add that since PHP is so dynamically-typed and prefers to cock programs up at run time instead of letting them be robustly specified from the get go, I once thought I *could* do this anyway. It's a valid syntax, but the first time one of my "exceptions" was thrown it blew up.
 [2015-02-12 00:41 UTC] codedokode at gmail dot com
I don't like the idea. It only makes things more confusing and you can use snippets in a code editor to save keystrokes anyway.
 [2015-08-27 20:26 UTC] nikic@php.net
-Status: Open +Status: Wont fix
 [2015-08-27 20:26 UTC] nikic@php.net
Marking as Won't Fix, as I doubt we wish to further encourage throwing of unspecific exception types.
 
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Thu May 13 16:01:23 2021 UTC