内容简介:你什么时候需要包含POST和GET方法作为函数的参数?翻译自:https://stackoverflow.com/questions/1354691/php-get-and-post-in-functions
你什么时候需要包含POST和GET方法作为函数的参数?
When do you you need to include POST and GET methods as parameters to functions?
我会说“从不”:$_GET和$_POST就是所谓的 superglobals :它们存在于整个脚本中;这意味着它们存在于函数/方法中.
特别是,您不需要
global
关键字.
仍然,依赖于函数/方法中的那些是非常糟糕的做法:您的函数/方法通常不应该依赖于未作为参数传递的任何东西.
我的意思是 ;考虑这两个功能:
function check_login_password()
{
$login = $_GET['login'];
$password = $_GET['password'];
// Work with $login and $password
}
和
/**
* Check login and password
*
* @param $login string
* @param $password string
* @return boolean
*/
function check_login_password($login, $password)
{
// Work with $login and $password
}
好的,对于第一个,你不必传递两个参数……但是这个函数不会是独立的,并且在你必须检查几个没有的登录/密码的任何情况下都不会起作用来自$_GET.
使用第二个函数,调用者负责传递正确的参数;这意味着他们可以来自你想要的任何地方:功能总是能够完成它的工作.
翻译自:https://stackoverflow.com/questions/1354691/php-get-and-post-in-functions
以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网
本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。
The Algorithmic Beauty of Plants
Przemyslaw Prusinkiewicz、Aristid Lindenmayer / Springer / 1996-4-18 / USD 99.00
Now available in an affordable softcover edition, this classic in Springer's acclaimed Virtual Laboratory series is the first comprehensive account of the computer simulation of plant development. 150......一起来看看 《The Algorithmic Beauty of Plants》 这本书的介绍吧!