...

View Full Version : static scope problems ??



PHPycho
08-31-2007, 06:23 AM
Hello forums!!
I had the following code running under the php5 server(With E_STRICT error reporting)
Code:

<?php
class Test{
private static $list;

private function __construct(){

}

public static function set_msg($msg)
{
self::$list[] = $msg;
}

public static function reset_msg()
{
unset(self::$list);
}

public static function get_msg()
{
return self::$list;
}

public static function test1(msg)
{
self::set_msg($msg);
}

public static function test2(msg)
{
self::set_msg($msg);
}

}
?>
Accessing portion:

<?php
// including class goes here..
Test::test1("Message1");
Test::test2("Message2");
print_r(Test::get_msg());
Test::reset_msg(); // this gives the error : "Fatal error: Attempt to unset static property Test::$list"
?>

Why did such error occur ? I didnt get any idea. Can anybody give a hint ?

Thanks in advance to all of you

GJay
08-31-2007, 07:55 AM
would setting it to 'null' rather than unsetting solve your problem?

daveyand
08-31-2007, 12:37 PM
best bet would be to do null.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum