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

$_GET/$_POST ? #21

Open
jbremer opened this issue Mar 18, 2013 · 2 comments
Open

$_GET/$_POST ? #21

jbremer opened this issue Mar 18, 2013 · 2 comments

Comments

@jbremer
Copy link

jbremer commented Mar 18, 2013

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
Copy link
Author

jbremer commented Mar 18, 2013

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 <jurriaanbremer@gmail.com>
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

@wujunze
Copy link

wujunze commented May 27, 2017

You're terrific

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants