Run configuration, script parameters

runconf.png
Tell me, please, how to set parameters.
I want to set $_GET['key']='zz' (or ?key=zz)
This forum posting page still bugged, so read from bottom to top.
Hello.

0
6 comments

I know it's almost ten years since last comment in this thread but its still in google first page so I want to share other people the solution I found witch fixed this problem .

So passing arguments to php cli using phpstorm configuration won't fix the problem cause you can't pass a variable value and tell php cli to assign it to variable . At least you can't do it directly . But by using some hacks you can do it really easily.

<?php

define("DEBUG", TRUE); // Activate debugging mode
if (
DEBUG === true // Checks if debugging mode is activated
&&
PHP_SAPI === "cli" // Checks if PHP script runs through CLI
)
parse_str(implode('&', array_slice($argv, 1)), $_GET); // Pass arguments to $_GET

Using debugging mode is not necessary, but it's a best practice at least for situations that I don't want to delete some "debugging specific codes" that I wrote before deployment.

References :

2

When using Php Script configuration, parameters are accessed like from the command line, via $argv, see http://php.net/manual/en/reserved.variables.argv.php.
If you want to test parameters passed via $_GET, you need to run your script on server (using PHP Web Application Run/Debug configuration where you can specify URL to open with parameters).

0
Avatar
Permanently deleted user

Hello OZ,

You can set necessary values manually.

In such manner, for example.

if(isset($argv['debug'])){
    $_GET['key'] = 'value';
    $_POST['key'] = 'value';
}


Thank you for feedback!

0

Heh, I can write even easily: $_GET['key']='value'; :) But it's not usable for testing completed scripts.

0

As Serge already mentioned, PHP Script run configuration is for running scripts in CLI mode where you cannot pass GET/POST parameters automatically (unless you set them in your code directly).

You can easily pass GET parameters when using PHP Web Application run configuration -- just add them to the script URL (Start URL field). In your example it will be something like:
/test2.php?key=zz

As for POST parameters ... I guess this is the right ticket to watch: http://youtrack.jetbrains.net/issue/WI-5175?projectKey=WI

0

I have not enough experience with running php in CL, and now I understand that this idea can not be normaly done, because of CLI restrictions.
Thanks for tips, excuse me for this stupid theme :)

0

Please sign in to leave a comment.