php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #36491 have abstract class instatiation throw exception
Submitted: 2006-02-22 23:42 UTC Modified: 2006-02-23 00:28 UTC
From: aarone at klamathsystems dot com Assigned:
Status: Not a bug Package: Feature/Change Request
PHP Version: 5.1.2 OS: *
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: aarone at klamathsystems dot com
New email:
PHP Version: OS:

 

 [2006-02-22 23:42 UTC] aarone at klamathsystems dot com
Description:
------------
would like to have abstract class instatiation throw exception instead of raise a fatal error.

One use case would be dynamic library loading when the application has to discover which library it needs.

What are the obstacles to having exceptions caught for runtime errors such as attempting to instantiate an abstract class?  I could probably think of other instances (especially of older functions that could be upgraded to php5) that could benefit for the robustness this would allow.

If the tradeoff is for speed or efficiency, that's understandable, but it would be nice to have an exception that could be caught and recovered from instead of a fatal error.

Example below:

Reproduce code:
---------------
abstract class Foo
{
}

class Bar extends Foo
{}

try
{
  $foo = new Foo();
}
catch (Exception e)
{
  //Foo is an abstract class, use concrete class Bar instead

  $foo = new Bar();
}


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-02-23 00:28 UTC] helly@php.net
Write you own language.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Oct 31 23:01:28 2024 UTC