tohokuaikiのチラシの裏

技術的ネタとか。

[*]PHP4とPHP5のClass静的なMethodコールの違い

<?php
error_reporting(E_ALL);
class Hoge
{
	var $str = "aaaaaaaa";
	
	function test()
	{
		echo $this->str."\n";
	}
}

Hoge::test();

ってやると、

  1. PHP4

Notice: Undefined variable: this in /************************/test.php on line 9
ってなるけど、

  1. PHP5

Fatal error: Using $this when not in object context in /************/test.php on line 9

ってなる。ふーん。確かに挙動としてはPHP5の方が正しい。