hhvm icon indicating copy to clipboard operation
hhvm copied to clipboard

class_alias is broken with interfaces and abstract classes

Open adrianheine opened this issue 12 years ago • 4 comments

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.

adrianheine avatar Apr 24 '14 13:04 adrianheine

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 avatar Apr 25 '14 07:04 elgenie

@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?

adrianheine avatar Apr 25 '14 07:04 adrianheine

this bug affects me too, I stumbled upon it recently while working on TYPO3 CMS compatibility with HHVM.

tmotyl avatar Apr 27 '14 15:04 tmotyl

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.)

jdelong avatar May 15 '14 16:05 jdelong