Skip to content

Instantly share code, notes, and snippets.

@jwoschitz
Created May 5, 2014 22:09
Show Gist options
  • Save jwoschitz/bba710a35418e701636d to your computer and use it in GitHub Desktop.
Save jwoschitz/bba710a35418e701636d to your computer and use it in GitHub Desktop.
Workaround for get_parent_class in hhvm if spl_autoloader is used
<?php
spl_autoload_register(function ($class) {
// in hhvm, this will not get executed
include 'parent_file.php';
});
// this will return false in hhvm due to https://github.com/facebook/hhvm/issues/2097
var_dump(get_parent_class('C'));
// this works in hhvm (should be considered only as a temp workaround)
// see https://github.com/facebook/hhvm/blob/master/hphp/runtime/ext/ext_spl.cpp#L173 for implementation details
var_dump(array_shift(class_parents('C')));
<?php
class B {}
class C extends B {}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment