0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

global命令, static命令

Posted at

はじめに

PHPのglobal命令, static命令に関して整理する。

global命令

ローカル変数を強制的にグローバル変数に割り当てる。

global.php
$x = 10;

function checkScope() {
    global $x;
    return ++$x;
}

print checkScope(); // 11
print $x; // 11 

static命令

静的変数を定義する。

static.php
function checkStatic() {
    Static $x = 0;
    return ++$x;
}

print checkStatic(); // 1
print checkStatic(); // 2
print $x; // null
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?