php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #55424 Fatal error when calling a method from a trait that is defined in parent class
Submitted: 2011-08-15 15:56 UTC Modified: 2011-08-15 22:20 UTC
From: Jared dot Williams1 at ntlworld dot com Assigned: gron (profile)
Status: Closed Package: Scripting Engine problem
PHP Version: 5.4SVN-2011-08-15 (SVN) OS: Ubuntu x64 11.04
Private report: No CVE-ID: None
 [2011-08-15 15:56 UTC] Jared dot Williams1 at ntlworld dot com
Description:
------------
A fatal error occurs when a method is called from a trait, which is implemented 
in the parent class of the class that utilises the trait.

Feels related to #55355 that was fixed.

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

	trait Required
	{
		function setRequired()
		{
			$this->setAttribute('required', true);
			return $this;
		}
		
		abstract function setAttribute($name, $value);
	}	
	
	class Input
	{
		protected $attributes = [];
		
		function setAttribute($name, $value)
		{
			$this->attributes[$name] = $value;
		}
	}
	
	class Text extends Input
	{
		use Required;
	}
	
	$t = new Text();
	$t->setRequired();



Expected result:
----------------
No fatal error.

Actual result:
--------------
PHP Fatal error:  Call to undefined method Text::setAttribute() in 
/home/jared/Temp/trait2.php on line 7

Fatal error: Call to undefined method Text::setAttribute() in 
/home/jared/Temp/trait2.php on line 7


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2011-08-15 21:07 UTC] php-bugs at majkl578 dot cz
With the same test script, I'm getting this error:
Fatal error: Cannot make non abstract method Input::setAttribute() abstract in class Text in /www/temp.php on line 27
 [2011-08-15 22:16 UTC] gron@php.net
Automatic comment from SVN on behalf of gron
Revision: http://svn.php.net/viewvc/?view=revision&amp;revision=314981
Log: Bug #55424	Fatal error when calling a method from a trait that is defined in parent class and required by using an abstract method in the trait.
# The method got unconditionally deleted from the class, since it was assumed that we override it, but we did not in case of abstract methods coming from a trait. Thus, dont delete when we try to merge in an abstract method.
 [2011-08-15 22:20 UTC] gron@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: gron
 [2011-08-15 22:20 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.

Yes, I introduced that regression in svnrev, 314943 and it should now be fixed per  
314981.
http://svn.php.net/viewvc?view=revision&revision=314981

Looks like there is a big hole in our test coverage :-/
Thanks for reporting!
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Apr 23 10:01:29 2024 UTC