PHPPHP icon indicating copy to clipboard operation
PHPPHP copied to clipboard

$_GET/$_POST ?

Open jbremer opened this issue 11 years ago • 2 comments

I've been trying to get $_GET/$_POST support working for the entire day already, but I don't seem to be very lucky at this, unfortunately.

It definitely doesn't seem to be supported by default, so I tried to integrate it myself. I've tried the following approaches, without much luck. Would you guys be able to tell me what's up?

  • Add/Dump $_GET/$_POST in Executor.php's execute function, at the point where $scope->symbolTable is assigned.
  • Adding array's/Zval::ptrFactory's/Zval:factory's/Zval::<other stuff> to $this->symbolTable in ExecutorGlobals.php's __construct.
  • Dumping data in OpLines/FetchGlobalVariables.php's execute handler, to receive a notification of reading a global.
  • Some other stuff..

Other than that, I'm really amazed by how clean the PHP code is, very good job on that one! Hopefully globals will be supported soon.

Also, I noticed that var_dump($GLOBALS); results in an infinite loop.

Cheers, Jurriaan

jbremer avatar Mar 18 '13 18:03 jbremer

Ok, I worked on some more testing. It appears that some stuff messes up when initializing the array's in ExecutorGlobals.php. However, we can cheat by adding some hacky stuff to Zval/Variable.php. The following patch atleast allows one to use $_GET['cmd'] and similar. However, var_dump($_GET); doesn't seem to work.

I'd do a pull request, but I'm pretty sure this is not code you'll want in your code base, as you'll probably want a proper fix. For me, the following seems to be good enough. Also, do note that for some reason I couldn't just use $$varName (the variable variable names thingy.) Not sure what's up with that, but oh well.

From <some-revision> Mon Sep 17 00:00:00 2001
From: Jurriaan Bremer <[email protected]>
Date: Mon, 18 Mar 2013 19:49:59 +0100
Subject: [PATCH] hacky fix for global php superglobals

---
 .../PHPPHP/lib/PHPPHP/Engine/Zval/Variable.php | 19 ++++++++++++++++---
 1 file changed, 16 insertions(+), 3 deletions(-)

diff --git a/PHPPHP/lib/PHPPHP/Engine/Zval/Variable.php b/PHPPHP/lib/PHPPHP/Engine/Zval/Variable.php
index 7210b1b..9bf261a 100644
--- a/PHPPHP/lib/PHPPHP/Engine/Zval/Variable.php
+++ b/PHPPHP/lib/PHPPHP/Engine/Zval/Variable.php
@@ -48,10 +48,23 @@ class Variable extends Zval {
             $this->zval = $ci->fetchStaticVariable($varName);
         } else if (self::SCOPE_GLOBAL === $this->scope) {
             $symbolTable = $this->executor->executorGlobals->symbolTable;
-            if (!isset($symbolTable[$varName])) {
-                $this->zval = Zval::ptrFactory();
+            $tbl = array(
+                '_GET' => $_GET,
+                '_POST' => $_POST,
+                '_SERVER' => $_SERVER,
+                '_REQUEST' => $_REQUEST,
+                '_FILES' => $_FILES,
+                '_COOKIE' => $_COOKIE,
+                '_SESSION' => $_SESSION,
+                '_ENV' => $_ENV,
+            );
+            if (isset($symbolTable[$varName])) {
+                $this->zval = Zval::ptrFactory($symbolTable[$varName]);
+            } else if(isset($tbl[$varName])) {
+                $symbolTable[$varName] = $tbl[$varName];
+                $this->zval = Zval::ptrFactory($tbl[$varName]);
             } else {
-                $this->zval = $symbolTable[$varName];
+                $this->zval = Zval::ptrFactory();
             }
         } else if ($varName == 'this') {
             $this->zval = Zval::lockedPtrFactory($this->executor->getCurrent()->ci);
-- 
1.8.0.msysgit.0

jbremer avatar Mar 18 '13 18:03 jbremer

You're terrific

wujunze avatar May 27 '17 10:05 wujunze