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

In "PHP7 mode", instanceof $type does not work for $type = 'Throwable' #7537

Closed
ezzatron opened this issue Dec 8, 2016 · 7 comments
Closed
Assignees

Comments

@ezzatron
Copy link

ezzatron commented Dec 8, 2016

FYI, this issue is preventing PHPUnit "skipped" tests from functioning, because it compares exceptions using instanceof against a variable containing 'Throwable'.

EDIT: Changed hhvm.php.all=1 to hhvm.php7.all=1.

HHVM Version

HipHop VM 3.15.2 (rel)
Compiler: tags/HHVM-3.15.2-0-g83ac3e5e3f5657be0cf4c55884044f86a7818b90
Repo schema: 608339137764e8365964a1adaa7a27d125b6076f

Standalone code, or other way to reproduce the problem

IMPORTANT: Code must be run with the INI setting hhvm.php7.all=1.

<?php

$e = new Exception();
$type = 'Throwable';

var_dump($e instanceof Throwable);
var_dump($e instanceof $type);

Expected result

bool(true)
bool(true)

Actual result

With the INI setting hhvm.php7.all=1:

bool(true)
bool(false)
@photodude
Copy link
Contributor

also an issue in hhvm 3.12.0 - 3.13.2 in php7 mode
https://3v4l.org/eZYqZ

and hhvm 3.15.3-3.16.0-dev in php7 mode

@mofarrell please remove the php5 incompatibility tag as this is only a php 7 mode issue.
see this build showing the correct behavior for php5 mode with both returning false

@ezzatron
Copy link
Author

@photodude Does that mean 3v4l.org has HHVM "PHP 7 mode" support now? How do you enable/disable it?

@photodude
Copy link
Contributor

@ezzatron 3v4l.org has enabled HHVM's PHP 7 mode by default. Read this feature request (and please contribute to that discussion) https://3v4l.uservoice.com/forums/219058-general/suggestions/16257685-hhvm-in-php-5-mode

@jwatzman
Copy link
Contributor

jwatzman commented Feb 2, 2017

Briefly looked into this. It isn't just Throwable, it's all the new classes in PHP7. HHVM implements that with a parser-level aliasing mechanism into the SystemLib namespace (where the classes reside even in PHP5 mode). It looks like instanceof with a dynamic argument doesn't respect that?

<?php

echo "Exception:\n";
$e = new Exception();
$type = 'Throwable';
$type2 = '\__SystemLib\Throwable';

var_dump($e instanceof Throwable);
var_dump($e instanceof $type);
var_dump($e instanceof $type2);


echo "DivisionByZeroError:\n";
$e = new DivisionByZeroError();
$type = 'DivisionByZeroError';
$type2 = '\__SystemLib\DivisionByZeroError';

var_dump($e instanceof DivisionByZeroError);
var_dump($e instanceof $type);
var_dump($e instanceof $type2);
Exception:
bool(true)
bool(false)
bool(true)
DivisionByZeroError:
bool(true)
bool(false)
bool(true)

@paulbiss
Copy link
Contributor

paulbiss commented Feb 3, 2017

It's also true of all the the HH specific classes we import via the same mechanism. https://3v4l.org/lY1R1

@jwatzman
Copy link
Contributor

jwatzman commented Feb 3, 2017

It's a somewhat less of a big deal for the Hack-specific ones though since doing this is much less common/useful given Hack's typing system (and is totally banned in strict mode).

@fredemmott
Copy link
Contributor

fredemmott commented May 9, 2017

Problems aren't just for dynamic usages - see https://3v4l.org/fKiQ3 #6747

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

7 participants