Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Namespace resolution broken inside anonymous classes #8319

Closed
thekid opened this issue Sep 10, 2018 · 2 comments
Closed

Namespace resolution broken inside anonymous classes #8319

thekid opened this issue Sep 10, 2018 · 2 comments

Comments

@thekid
Copy link
Contributor

thekid commented Sep 10, 2018

HHVM Version

$ hhvm --version
HipHop VM 3.28.1 (rel)
Compiler: 1535652629_477638284
Repo schema: ff51ed686b7d3c44bf3f95bda084cb2afadcecb9

$ hh_client --version
hh--3.28.1 Thu Aug 30 20:13:18 2018

Operating System and Version

Debian Stretch

Standalone code, or other way to reproduce the problem

test.php:

<?php
use lang\{Value, IllegalStateException};

spl_autoload_register(function($class) {
  echo "Loading $class\n";
  include(strtr($class, '\\', DIRECTORY_SEPARATOR).'.php');
});

$v= new class() implements Value {
  public function toString() { throw new IllegalStateException('Cannot render string'); }
};

var_dump($v->toString());

lang/Value.php:

<?php namespace lang;

interface Value {
}

lang/IllegalStateException.php:

<?php namespace lang;

class IllegalStateException extends \Exception {
}

Actual result

$ hhvm test.php
Loading lang\Value
Loading IllegalStateException

Warning: include(IllegalStateException.php): File not found in /home/friebe/test.php on line 6

Fatal error: Uncaught Error: Class undefined: IllegalStateException in /home/friebe/test.php:10

The problem can be clearly seen in the second Loading output - it should include the namespace, but doesn't. This code works fine with older HHVM versions, e.g. 3.21.

Expected result

$ php7.0 test.php
Loading lang\Value
Loading lang\IllegalStateException
PHP Fatal error:  Uncaught lang\IllegalStateException: Cannot render string in /home/friebe/test.php:10
@thekid
Copy link
Contributor Author

thekid commented Sep 10, 2018

Might also be related to #7878

@thekid
Copy link
Contributor Author

thekid commented Sep 10, 2018

Oops, sorry, seems to be a duplicate of #8275; although a slightly different case: This is related to code inside the functions, while the other bug is about type hints.

Might be the same cause, close this at will.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants