PHPのstatic

            <div class="section">

以前書いた記事

http://d.hatena.ne.jp/tnnsst35/20091202/1259761913

どうやら勘違いしていたようです。

<b>test.php</b>
class test {
 public function display($message = '') {
  echo htmlspecialchars($message) . "\n";
  return true;
 }
}
 
<b>hoge.php</b>
require_once('test.php');
test::display('aaa');
 
%php hoge.php
aaa

static宣言してないのに、test::display('aaa')みたいにメソッドを使えるんだな。

なんか不思議。

あ、もちろん以下のようにしても同じ動作をした。

<b>test.php</b>
class test {
 static function display($message = '') {
  echo htmlspecialchars($message) . "\n";
  return true;
 }
}
 
<b>hoge.php</b>
require_once('test.php');
test::display('aaa');
 
%php hoge.php
aaa