Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@shoyan
Created February 7, 2014 08:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shoyan/8859080 to your computer and use it in GitHub Desktop.
Save shoyan/8859080 to your computer and use it in GitHub Desktop.
static修飾子の簡単なサンプル
<?php
/*
* static修飾子を使うとあたかもインスタンスのメンバ変数のような振る舞いができる
*/
class Hoge
{
static $hoge = null;
function add()
{
self::$hoge++;
}
function get()
{
return self::$hoge;
}
}
Hoge::add();
Hoge::add();
var_dump(Hoge::get()); // 2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment