class_alias is broken with interfaces and abstract classes
I have the following file:
<?php
class A {}
class_alias( 'A', 'B' );
interface UserOfA {
public function someMethod( B $a );
}
class ActualUserOfA implements UserOfA {
public function someMethod( A $a ) {
}
}
I get the following fatal error:
HipHop Fatal error: Declaration of ActualUserOfA::someMethod() must be compatible with that of UserOfA::someMethod()
I would expect the engine to take the alias into account when checking signatures for interfaces.
Note, however, that a class ActualUserOfA extending a class UserOfA with an empty implementation of someMethod works:
<?php
class A {}
class_alias( 'A', 'B' );
class UserOfA {
public function someMethod( B $a ) {
}
}
class ActualUserOfA extends UserOfA {
public function someMethod( A $a ) {
}
}
If UserOfA is an abstract class and has an abstract someMethod, it fails again:
<?php
class A {}
class_alias( 'A', 'B' );
abstract class UserOfA {
abstract public function someMethod( B $a );
}
class ActualUserOfA extends UserOfA {
public function someMethod( A $a ) {
}
}
The latter does not work in Zend, either.
In both HHVM and PHP5, There are no compatibility checks done for non-abstract methods. Interfaces are being compatibility-checked as a collection of abstract methods.
On Thursday, April 24, 2014, Adrian Lang [email protected] wrote:
I have the following file:
Eugene
@elgenie If I understand you correctly that explains why extending the non-abstract base class works and the others not, i. e., the actual shape of the bug. It's still a bug, though, right?
this bug affects me too, I stumbled upon it recently while working on TYPO3 CMS compatibility with HHVM.
I've made a patch to make this compatible in non-RepoAuthoritative mode for now. (We could do RepoAuthoritative mode, but we have very limited support for class_alias in that mode anyway.)