Note that there are some explanatory texts on larger screens.

plurals
  1. POPHP how to use string as superglobal
    primarykey
    data
    text
    <p>I'm building a small abstract class that's supposed to make certain tasks easier.</p> <p>For example: $var = class::get('id'); would run check if there's pointer id in the $_GET, returning a string or array according to parameters. This should also work for post and request and maby more.</p> <p>I'm doing it in the way there's function for all the superglobals. I'm using get as example:</p> <p>get function gets a pointer as parameter, it calls fetchdata function and uses the pointer and "$_GET" as the parameters.</p> <p>fetchdata is supposed to just blindly use the string it got as superglobal and point to it with the other param. Then check if it exists there and return either the value or false to get function, that returns the value/false to caller.</p> <p>Only problem is to get the string work as superglobal when you don't know what it is. I did this before with a switch that checked the param and in case it was "get", it set $_GET to value of another variable. However I don't want to do it like that, I want it to be easy to add more functions without having to touch the fetchdata.</p> <p>I tried $method = eval($method), but it didn't work. ($method = "$_GET"), any suggestions?</p> <p>EDIT: Sorry if I didn't put it clear enough. I have a variable X with string value "$_GET", how can I make it so X gets values from the source described in the string?</p> <p>So simply it's </p> <p>$X = $_GET if X has value "$_GET"</p> <p>$X = $_POST if X has value "$_POST"</p> <p>I just don't know what value X has, but it needs to get data from superglobal with the same name than its value.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload