Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Cannot use ‘abstract’ as method modifier

Description

When resolving name conflicts during trait imports, it is not possible to use abstract with the as keyword. The situation is actually confusing: abstract may be the name of the alias, or it could also be understood as the modifier.

The same situation arise with abstract, final or readonly. On the other hand, it is valid to use the visibility modifier to actually change the visibility on the alias.

Example

<?php
trait T1 {
	function foo() {}
}
class C1 {
	use T1 {
		T1::foo as abstract;
	}
}
?>

Alternatives

  • Use another name than abstract for the alias.
  • Use another name than abstract for the original method.

In more recent PHP versions, this error message is now :ref:cannot-use-"abstract"-as-method-modifier-in-trait-alias.