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
 [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

Add a Patch

Pull Requests

Add a Pull Request

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 May 16 06:01:31 2024 UTC