php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #55355 Unexpected fatal error when using abstract functions with traits
Submitted: 2011-08-03 13:47 UTC Modified: 2011-08-15 11:18 UTC
From: Jared dot Williams1 at ntlworld dot com Assigned: gron (profile)
Status: Closed Package: Class/Object related
PHP Version: 5.4SVN-2011-08-03 (SVN) OS: Ubuntu 11.04
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: Jared dot Williams1 at ntlworld dot com
New email:
PHP Version: OS:

 

 [2011-08-03 13:47 UTC] Jared dot Williams1 at ntlworld dot com
Description:
------------
When resolving trait abstract methods, it seems the class hierarchy is not 
checked, resulting in a fatal error if an abstract method isn't implemented 
directly in the class that is utilising the trait.



Test script:
---------------
<?php

	trait ATrait
	{
		function bar()
		{
			$this->foo();
		}

		abstract function foo(); 
	}

	class Base
	{
		function foo() { }
	}

	class Child extends Base
	{
		use ATrait;	
	}


Actual result:
--------------
PHP Fatal error:  Cannot make non abstract method Base::foo() abstract in class 
Child in /home/jared/Temp/trait.php on line 21

Fatal error: Cannot make non abstract method Base::foo() abstract in class Child 
in /home/jared/Temp/trait.php on line 21


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2011-08-15 11:16 UTC] gron@php.net
Automatic comment from SVN on behalf of gron
Revision: http://svn.php.net/viewvc/?view=revision&amp;revision=314943
Log: Fixed Bug #55355: Inheritance chain was not regarded when checking whether the abstract method of a trait is satisfied.
 [2011-08-15 11:18 UTC] gron@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: gron
 [2011-08-15 11:18 UTC] gron@php.net
This bug has been fixed in SVN.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.

 For Windows:

http://windows.php.net/snapshots/
 
Thank you for the report, and for helping us make PHP better.

Thanks, is fixed per http://svn.php.net/viewvc?view=revision&revision=314943
 [2012-04-18 09:49 UTC] laruence@php.net
Automatic comment on behalf of gron
Revision: http://git.php.net/?p=php-src.git;a=commit;h=f4d3d6c439bc71263f9201f7030d3da7eb6dfe58
Log: Fixed Bug #55355: Inheritance chain was not regarded when checking whether the abstract method of a trait is satisfied.
 [2012-07-24 23:40 UTC] rasmus@php.net
Automatic comment on behalf of gron
Revision: http://git.php.net/?p=php-src.git;a=commit;h=f4d3d6c439bc71263f9201f7030d3da7eb6dfe58
Log: Fixed Bug #55355: Inheritance chain was not regarded when checking whether the abstract method of a trait is satisfied.
 [2013-11-17 09:36 UTC] laruence@php.net
Automatic comment on behalf of gron
Revision: http://git.php.net/?p=php-src.git;a=commit;h=f4d3d6c439bc71263f9201f7030d3da7eb6dfe58
Log: Fixed Bug #55355: Inheritance chain was not regarded when checking whether the abstract method of a trait is satisfied.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Wed Feb 05 16:01:30 2025 UTC