faizulbari Posted February 3, 2007 Share Posted February 3, 2007 <?php class foo { public static $arr = array(0 => 1,2,2,3,4); public function foo() { } public function test() { echo "X".$arr[3]."X"; } } ?> <?php $f = new foo(); $f->test(); ?> it should print "X2X" but it prints "XX" i can't understand whats the problem here??? plz help Link to comment https://forums.phpfreaks.com/topic/36911-solved-problem-with-a-static-array-__/ Share on other sites More sharing options...
hvle Posted February 3, 2007 Share Posted February 3, 2007 yep, that's because static is special, you have to access via class name: public function test() { echo "X".self::$arr[3]."X"; } Link to comment https://forums.phpfreaks.com/topic/36911-solved-problem-with-a-static-array-__/#findComment-176083 Share on other sites More sharing options...
faizulbari Posted February 3, 2007 Author Share Posted February 3, 2007 thank u very much Link to comment https://forums.phpfreaks.com/topic/36911-solved-problem-with-a-static-array-__/#findComment-176087 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.