是PHP中的$ _POST真正超全球性吗? [英] is $_POST in php truly superglobal?

查看:92
本文介绍了是PHP中的$ _POST真正超全球性吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我为什么要问这个?我正在努力理解php的超全局性概念... $ _POST的数组数据/变量仅可用于表单回传到的文件.

Why am i asking this ? I'm trying hard to fathom php's superglobal concept ... array data/variables for $_POST are only available to the file to which the form posts back.

它们不适用于网站或应用程序中的任何其他文件.

They are not available to any of the other files in the Website or Application.

然后,为什么/how是$ _POST一个超全局变量,按其直觉含义,它应该表示任何位置/任何位置都可用的变量,包括未定义网站/应用程序中的所有文件.

Then why /how is $_POST a superglobal which by it's intutive meaning should mean any variable that is available anywhere / everywhere including all files in a website/ Application where it was not defined.

有人可以向我解释其背后的逻辑吗?

Can someone please explain me the logic behind this ?

我特别希望找到一种直接方法(即简单地调用/声明变量,而不是间接方法(如包含变量的文件等)来在网站/应用程序中的所有文件中共享变量.

I'm particularly looking to find a direct approach (i.e simply calling/declaring the variable and not indirect approaches like inclding the file containing the variable etc.)to share variables throughout all files in the Website/ Application.

推荐答案

您对超全局性的直观定义与PHP使用该术语的方式不匹配. PHP中"superglobal"的定义是该变量在脚本的所有作用域中均可用.普通全局变量和超全局变量之间的唯一区别是,您不必使用global关键字即可在函数或方法中访问它们.

Your intuitive definition of superglobal doesn't match how PHP uses the term. The definition of "superglobal" in PHP is that the variable is available in all scopes within the script. The only difference between ordinary global variables and superglobals is that you don't have to use the global keyword to access them within a function or method.

请参见文档.

这篇关于是PHP中的$ _POST真正超全球性吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆