Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder
    Join Date
    Dec 2005
    Posts
    217
    Thanks
    1
    Thanked 0 Times in 0 Posts

    static scope problems ??

    Hello forums!!
    I had the following code running under the php5 server(With E_STRICT error reporting)
    Code:
    PHP 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 Code:
    <?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

  • #2
    Senior Coder
    Join Date
    Sep 2005
    Posts
    1,791
    Thanks
    5
    Thanked 36 Times in 35 Posts
    would setting it to 'null' rather than unsetting solve your problem?
    My thoughts on some things: http://codemeetsmusic.com
    And my scrapbook of cool things: http://gjones.tumblr.com

  • #3
    New Coder
    Join Date
    Jun 2007
    Posts
    23
    Thanks
    0
    Thanked 0 Times in 0 Posts
    best bet would be to do null.
    PHP / CSS / Perl / XML / XHTML

    For cheap ipod touch go to protella.com


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •