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

XHP array specification is stripped #4961

Open
fredemmott opened this issue Mar 5, 2015 · 1 comment
Open

XHP array specification is stripped #4961

fredemmott opened this issue Mar 5, 2015 · 1 comment

Comments

@fredemmott
Copy link
Contributor

<?hh

class bar {
  protected static function __xhpAttributeDeclaration(): array {
    return array();
  }
}

class :foo extends bar {
  const ATTR_TYPE_ARRAY = 4; // :x:composable-element::TYPE_ARRAY
  attribute
    array<int, string> myarray;
  public static function main() {
    $decl = self::__xhpAttributeDeclaration()['myarray'];

    // See https://gist.github.com/fredemmott/cf2d387208463de2cca0

    $type = $decl[0];
    var_dump($type === self::ATTR_TYPE_ARRAY); // bool(true)
    $array_spec= $decl[1];
    /*
     * Actual: NULL
     * Expected:
     *  [
     *    0 => TYPE_INT,
     *    1 => TYPE_STRING,
     *    2 => null,
     *  ]
     */
    var_dump($array_spec);
  }
}

:foo::main();

This means that array attributes are not validated.

@fredemmott
Copy link
Contributor Author

I'm going to remove the validation from xhp-lib for perf reasons, but ideally this data would still be there for reflection.

fredemmott added a commit to hhvm/xhp-lib that referenced this issue Mar 5, 2015
- it worked on PHP5, but not HHVM. As we now require HHVM, it's pointless
  facebook/hhvm#4961
- iterating over containers for typechecks is likely to be a perf issue
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

1 participant