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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
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-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 26 15:01:56 2024 UTC