|
Posted by Alexey Kulentsov on 08/01/07 07:56
amygdala wrote:
> Now, if $_POST variables are sent to some page and are needed by the called
> upon function in the appropriate class, would it be bad practice to simply
> extract those $_POST variables from the superglobal $_POST inside this
Passing parameters as global variables is fully idiotic way. Never do this.
> function? Preferably I would like to send the $_POST variables as arguments
> to the function, but I'm not sure how to implement this correctly, nor am I
> even completely sure as to why this would be better practice, other than
> that the function will only accept predefined arguments.
Better practice: pass to function only needed parameters, not all
$_POST array. Test parameters types in function.
In all my code I have '$_GET' string only 1 (one) time and '$_POST'
string only 1 (one) time, in my utils::getArgs() function. And only page
component uses it and then pass needed data to child components.
/// Get script arguments
/**
* Depends on calling method.
* Suports GET, POST and command line calling.
* Removes magic_quotes_gps effect
*/
static function getArgs()
{
if(isset($_SERVER['REQUEST_METHOD']))
{
if($_SERVER['REQUEST_METHOD']=='POST')
$return=$_POST;
else $return=$_GET;
if(get_magic_quotes_gpc())
array_walk_recursive($return,create_function('&$value','$value=stripslashes($value);'));
return $return;
}else if(isset($_SERVER['CMDLINE']))
{
include_once 'parser.class.php';
$parser=new Parser($_SERVER['CMDLINE']);
$parser->readRegexp('[^ ]+([ ]+-[^ ]+)*[ ]+[^ ]+');
$retval=array();
while(strlen($parser->buffer))
{
if($parser->skipSpace()) continue;
if(!$retval[]=$parser->readRegexp('(("[^"]*")|[^ "]+)'))
break;
}
return $retval;
}
return array();
}
[Back to original message]
|