Skip to content

Commit

Permalink
interfaces can't have PHP4 constructors
Browse files Browse the repository at this point in the history
Summary:
Don't raise errors for them

fixes #8121

Reviewed By: markw65

Differential Revision: D7418115
  • Loading branch information
fredemmott committed Mar 28, 2018
1 parent aeb5357 commit 305fa86
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 1 deletion.
2 changes: 1 addition & 1 deletion hphp/runtime/vm/class.cpp
Expand Up @@ -1466,7 +1466,7 @@ void Class::setSpecial() {
return;
}

if (!(attrs() & AttrTrait)) {
if (!(attrs() & (AttrTrait | AttrInterface))) {
// Look for Foo::Foo() (old style constructor) declared in this class
// and deprecate warning if we are in PHP 7 mode
if (matchedClassOrIsTrait(m_preClass->name())) {
Expand Down
28 changes: 28 additions & 0 deletions hphp/test/slow/php7_bcbreak/php4-constructors.php
@@ -0,0 +1,28 @@
<?php

error_reporting(E_ALL | E_STRICT | E_DEPRECATED);

// No PHP4 constructor
interface foo {
public function foo();
}

// No PHP4 constructor
class bar implements foo {
public function foo() {}
}

// No PHP4 constructor
trait herp {
public function derp() {}
}

// PHP4 constructor via trait
class derp {
use herp;
}

// direct PHP4 constructor
class MyClass {
public function MyClass() {}
}
3 changes: 3 additions & 0 deletions hphp/test/slow/php7_bcbreak/php4-constructors.php.expectf
@@ -0,0 +1,3 @@
Deprecated: Methods with the same name as their class will not be constructors in a future version of PHP; MyClass has a deprecated constructor in %s/test/slow/php7_bcbreak/php4-constructors.php on line 26

Deprecated: Methods with the same name as their class will not be constructors in a future version of PHP; derp has a deprecated constructor in %s/test/slow/php7_bcbreak/php4-constructors.php on line 21
1 change: 1 addition & 0 deletions hphp/test/slow/php7_bcbreak/php4-constructors.php.ini
@@ -0,0 +1 @@
hhvm.php7.all=1

0 comments on commit 305fa86

Please sign in to comment.