3

I'm running HHVM 3.2.0 and trying to get access to GET and POST request parameters. The problem is, HHVM doesn't support access to PHP superglobals ($_GET, $_POST, $_SERVER, etc).

The only other way I know of getting access to request parameters in PHP is via the filter_input function, but is that really best practice (if I'm just using the raw filter)? It seems as though HHVM should support something cleaner than that. (What about Hack?)

Libbux
  • 1,711
  • 2
  • 12
  • 14
  • Does hhvm support [`php://input`](http://php.net/manual/en/wrappers.php.php)? – Jared Farrish Jul 22 '14 at 22:19
  • @JaredFarrish I don't believe so. Not directly at least. Source: http://docs.hhvm.com/manual/en/wrappers.php.php – Libbux Jul 22 '14 at 22:20
  • Have you tried it? I'm seeing examples around using `fopen()` with `php://memory`, which "appears" to be shown as not supported on that page. Also, there's [this documentation page](http://docs.hhvm.com/manual/en/features.commandline.io-streams.php), showing using three more listed on that page. That documentation looks pretty suspect to me. – Jared Farrish Jul 22 '14 at 22:33
  • @JaredFarrish No, but this all looks horrible. Reading request parameters is one of the principle operations of any script... How can it be so obscure? – Libbux Jul 22 '14 at 22:37
  • 1
    I'm looking around and there's an awful lot of projects that seem to support hhvm. Symfony, for instance, and I can't find anything [specific to the way it's setup](http://www.leaseweblabs.com/2014/05/symfony-hhvm-3-nginx-1-4-vs-php-5-5-apache-2-4/). – Jared Farrish Jul 22 '14 at 22:57
  • 1
    Do they not exist at all in HHVM? See [this post indicating that `$_POST` is available](http://hhvmhack.blogspot.com/2014/03/a-simple-tutorial.html). – elixenide Jul 23 '14 at 02:24

2 Answers2

4

HHVM absolutely supports superglobals in PHP code -- they're a really key part of PHP! The docs page you've linked to is simply wrong, and I've filed a bug to get it fixed.

In strict mode Hack code, superglobals are not supported; this cookbook example shows how you can access them via partial mode.

Josh Watzman
  • 7,060
  • 1
  • 18
  • 26
0

Seems like they added HH\global_get() to get global variables.

https://docs.hhvm.com/hack/reference/function/HH.global_get/

To put everything together

use namespace \Facebook\TypeSpec;

// get $_GET using global_get
function global_get_get(): darray<arraykey, mixed> {
  $spec = TypeSpec\darray(
    TypeSpec\arraykey(),
    TypeSpec\mixed(),
  );
  return $spec->assertType(\HH\global_get("_GET"));
}

nwarp
  • 731
  • 4
  • 8
  • 17