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

Throwable interface problems in namespaces #6747

Closed
jurchiks opened this issue Jan 12, 2016 · 5 comments
Closed

Throwable interface problems in namespaces #6747

jurchiks opened this issue Jan 12, 2016 · 5 comments

Comments

@jurchiks
Copy link
Contributor

test.php:

<?php
namespace test;

function a(\Throwable $t) {}

a(new \RuntimeException('foo'));
$ hhvm --no-config -d hhvm.php7.all=true test.php

Fatal error: Uncaught TypeError: Argument 1 passed to test\a() must be an instance of Throwable, RuntimeException given in /home/jsudmalis/test.php:6
Stack trace:
#0 /home/jsudmalis/test.php(8): test\a()
#1 {main}

It seems HHVM does not recognise Throwable inside a namespace. Since this is a class in __SystemLib, I'm worried this might be an issue with other classes there.

@jurchiks jurchiks changed the title Exception does not implement Throwable? Exception does not implement Throwable / Throwable interface does not exist Jan 12, 2016
@fredemmott
Copy link
Contributor

-d hhvm.php7.all=true needs to go before test.php, otherwise it goes into test.php's argv instead of being considered an HHVM option:

 hhvm --no-config -d hhvm.php7.all=true test.php
bool(false)
bool(true)
bool(true)

So RuntimeException does implement Throwable. interface_exists() fails because:

<?php
var_dump(interface_exists('Throwable'));
var_dump(interface_exists(Throwable::class));
var_dump(Throwable::class);
[fredemmott@devbig349 ~/test] hhvm --no-config -d hhvm.php7.all=true test.php
bool(false)
bool(true)
string(21) "__SystemLib\Throwable"

Also an issue, but probably much less important.

@jurchiks jurchiks changed the title Exception does not implement Throwable / Throwable interface does not exist Throwable interface problems in namespaces Jan 12, 2016
@fredemmott
Copy link
Contributor

heh, that's pretty bad D: we need to not auto-import it into the current namespace (like we do for hack stuff), but actually alias it.

@jurchiks
Copy link
Contributor Author

@fredemmott cleaned my comments up a bit, you can delete your first one as well, to keep the topic brief.

@fredemmott
Copy link
Contributor

Keeping it in, the Throwable::class vs 'Throwable' vs \Throwable could be useful for whoever works on this.

@fredemmott
Copy link
Contributor

https://3v4l.org/fKiQ3

<?php

namespace Foo;

$x = new \Exception();
var_dump($x instanceof \Throwable);

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

No branches or pull requests

3 participants