辣鸡

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::

About more complex situation using global variables..

Let's say we have two files:
a.php
<?php 
    
function a() { 
        include(
"b.php"); 
    }
    
a();
?>

b.php
<?php
    $b 
"something";
    function 
b() {
        global 
$b;
        
$b "something new";
    }
    
b();
    echo 
$b;
?>

You could expect that this script will return "something new" but no, it will return "something". To make it working properly, you must add global keyword in $b definition, in above example it will be:

global $b;
$b = "something";

posted on 2012-03-16 15:13  辣鸡  阅读(373)  评论(0编辑  收藏  举报