Home > Backend Development > PHP Tutorial > php在函数外声明global变量有什么用?

php在函数外声明global变量有什么用?

WBOY
Release: 2016-06-23 14:02:07
Original
941 people have browsed it

php wordpress global

php在函数外声明global变量有什么用?

我看wordpress的wp-settings.php文件中有这么一段:

/* * These can't be directly globalized in version.php. When updating, * we're including version.php from another install and don't want * these values to be overridden if already set. */global $wp_version, $wp_db_version, $tinymce_version, $required_php_version, $required_mysql_version;require( ABSPATH . WPINC . '/version.php' );
Copy after login


不懂,求解释,谢谢啦 ^_^

回复讨论(解决方案)

没有作用
并且在 wp-settings.php 中也没有看到
global $wp_version, $wp_db_version, $tinymce_version, $required_php_version, $required_mysql_version;
只有
require( ABSPATH . WPINC . '/version.php' );

没作用

global
$a = 1;
$b = 2;

function Sum()
{
    global $a, $b;

    $b = $a + $b;
}

Sum();
echo $b;
?>
以上脚本的输出将是“3”。在函数中声明了全局变量 $a 和 $b 之后,对任一变量的所有引用都会指向其全局版本。对于一个函数能够声明的全局变量的最大个数,PHP 没有限制。

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template