zoukankan      html  css  js  c++  java
  • differences between session variable and global variable

    The --maximum prefix is available for mysqld only and permits a limit to be placed on how large client programs can set session system variables. To do this, use a --maximum prefix with the variable name. For example, --maximum-max_heap_table_size=32M prevents any client from making the heap table size limit larger than 32M.

    The --maximum prefix is intended for use with system variables that have a session value. If applied to a system variable that has only a global value, an error occurs. For example, with --maximum-back_log=200, the server produces this error:

     
    Maximum value of 'back_log' cannot be set

    global is just a keyword to access a variable that is declared in the top level scope and isn't available in the actual scope. This hasn't anything to do with the session: do not persist between pages.

    $a = "test";
    function useGlobalVar(){
        echo $a;   // prints nothing, $a is not availabe in this scope
        global $a;
        echo $a;   // prints "test"
    }
    

    $GLOBALS is another way to access top-level scope variables without using the global keyword:

    $a = "test";
    function useGlobalVar(){
        echo $GLOBAL['a'];   // prints "test"
    }
    

    There's a bit of of confusion between global and superglobals: Superglobals (like $GLOBALS, $_REQUEST, $_SERVER) are available in any scope without you having to make a global declaration. Again, they do not persist between pages (with the exception of $_SESSION).

    $_SESSION is a Superglobal array that persist across different pages.

  • 相关阅读:
    乘法DAC一点知识
    #4 判断字符串是否为整数
    #3 不使用循环输出1到100
    #2 判断一个字符串是否包含重复字符
    #22 结语
    #1 组成互不相同且不重复的三位数
    #21 Python异常
    #19 re&jieba模块
    2020国庆正睿笔记
    2019正睿csp-s赛前冲刺
  • 原文地址:https://www.cnblogs.com/CreatorKou/p/9037728.html
Copyright © 2011-2022 走看看