Set $_GET['foo'] variable when calling a PHP script on CLI?

No, Its not possible via CLI. However you can manually assign the value to the $_GET variable.

No, Its not possible via CLI. However you can manually assign the value to the $_GET variable. OR you can use the command line arguments and assign them to the $_GET.

$_GET'data' = $argv; ^^That's a little bit manageable..

You can just do $_GET'foo' = 'bar'; to set it.

Assuming you have some code that is using $_GET'foo' to do something then the best way to handle it would be to extract that code into a class/method/function and then have context-specific scaffolding which gathers the relevant data from the environment and passes it into the code-block to do it's stuff. So let's say you had an inline PHP script like this: $foo = $_GET'foo'; // do what I need to do with $foo Then you could wrap this into a function function doBar( $foo ) { // do what I need to do with $foo } Your inline php script would now be $foo = $_GET'foo'; doBar( $foo ); And you could very easily write a CLI script to test this, either by setting $foo directly $foo = 'test value'; doBar( $foo ); Or by parsing the CLI inputs and getting foo from there instead. Basically, your code that does stuff (the Model in a traditional MVC) is isolated from its environment and can be used via an HTTP request, in a CLI script, in a unit test etc.One thing I would stay clear of is assigning your own values to the $_GET and $_POST superglobals.

It's smelly and a short-cut to giving you problems some way down the line.

The two options to set $_GET variables: simply have something like: blah This will set $_GET'foo' to bar. Or: Any information you will send with this form will be retrievable with $_GET.

1 Neither of which is at all applicable to the CLI. – ceejayoz Oct 28 at 14:58 1 Yeah, too quick to post. Have up-voted the proper answer.

– Dennis Oct 28 at 14:59.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions