php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #76020 Not fully implemented class only generates fatal without exception
Submitted: 2018-02-27 17:50 UTC Modified: 2018-02-27 19:25 UTC
From: elibyy at gmail dot com Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: 7.0.27 OS: Win/Nix
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: elibyy at gmail dot com
New email:
PHP Version: OS:

 

 [2018-02-27 17:50 UTC] elibyy at gmail dot com
Description:
------------
In PHP 7 the error flow was changed that any code (even fully breaking) will pass in a try... catch block
but if you create a class that implements an interface partially, you will get a fatal but no exception is thrown, and therefore breaks the script

The error message is:
Fatal error: Class B contains 1 abstract method and must therefore be declared abstract or implement the remaining methods (A::thing1)

Test script:
---------------
<?php
ini_set('error_reporting', E_ALL);
ini_set('display_errors', 1);

interface A {

	function thing();

	function thing1();

}

class B implements A {

	public function thing() {

	}
}

try{
	new B();
}catch(\Throwable $t){
	//expected to be catched
}


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2018-02-27 18:00 UTC] nikic@php.net
-Status: Open +Status: Not a bug -Package: PHP Language Specification +Package: Scripting Engine problem
 [2018-02-27 18:00 UTC] nikic@php.net
The fatal error to exception conversion occurs on a best-effort basis. Not every place can easily throw an exception instead of a fatal. This is one of them. If the technical issues are resolved at some point in the future, this will be changed to throw as well.

PS: The exception would occur at the point of the class declaration, not at the point of instantiation. As such, your particular example code would not work in any case.
 [2018-02-27 18:07 UTC] elibyy at gmail dot com
Hey,
This is understandable.
my main need is so that my exception handler will catch it and I will be able to know the cause of my 500
 [2018-02-27 19:25 UTC] nikic@php.net
@elibyy: A common workaround for fatals not going through the error handler is to register a shutdown handler and then check if error_get_last() contains a fatal error.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Sat Jul 12 05:01:33 2025 UTC