#1
  1. More powar to you!
    Devshed Novice (500 - 999 posts)

    Join Date
    Nov 2004
    Location
    United Kingdom
    Posts
    702
    Rep Power
    205

    Class/Object Unset Static Member/Property


    It's been a while since I was here! I'm returning to a little PHP as it's part of my Software Engineering course. Anyway, enough with the chit-chat, it's nice to be back.

    I'm having a little trouble with a customer object I've created, I want to provide a function to log the customer out, and I'd like to simply unset the object in my "manager" static class object.

    Currently I have a function called logoutCustomer... And it attempts to do:

    PHP Code:
    unset(self::$customer); 
    but throws an error:

    Code:
    Fatal error: Attempt to unset static property manager::$customer in C:\Program Files\wamp\www\wad_assignment2\libraries\manager.php on line 80
    What I'd like to know is... What's the best/safest way to "unset" the customer object?
    PHP Code:
    if($Tiredness TIREDNESS_MAX$CupOfTea++; 
    If you found what I've said helpful, I'm interested in reputation points!
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Jun 2007
    Posts
    1,513
    Rep Power
    1423
    I'd recommend using a default customer instance for this. Most applications will only function if there is a user representation as well. In your case I guess, the customer object represents your software's user, therfor I think a "guest customer" might be wise to have. Now if a user loggs out, you can simply set your static member (I just hope it's for a singleton?) to an instance representing this guest.

    Comments on this post

    • Tentuxius agrees : Your thoughts are much appreciated.
  4. #3
  5. More powar to you!
    Devshed Novice (500 - 999 posts)

    Join Date
    Nov 2004
    Location
    United Kingdom
    Posts
    702
    Rep Power
    205
    Good idea, I can see how a guest customer can work perfectly in an application.

    I'm actually just doing a small project and so I won't be able to take advantages of having a guest customer. It's actually a new idea to me, though I've probably seen this idea over and over!

    Thanks JClasen.

    Originally Posted by JClasen
    I'd recommend using a default customer instance for this. Most applications will only function if there is a user representation as well. In your case I guess, the customer object represents your software's user, therfor I think a "guest customer" might be wise to have. Now if a user loggs out, you can simply set your static member (I just hope it's for a singleton?) to an instance representing this guest.
    PHP Code:
    if($Tiredness TIREDNESS_MAX$CupOfTea++; 
    If you found what I've said helpful, I'm interested in reputation points!
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Jun 2007
    Posts
    1,513
    Rep Power
    1423
    Originally Posted by Tentuxius
    I'm actually just doing a small project and so I won't be able to take advantages of having a guest customer.
    Why? A guest user would mean an additional six lines of code for a derived class. (if even). Otherwhise you could only set your member as null. Unfortunately this'll mean lots of tests for your member to actually be an instance of "customer" or errors on about every call to a method of your non-object, if you leave out these tests..
  8. #5
  9. More powar to you!
    Devshed Novice (500 - 999 posts)

    Join Date
    Nov 2004
    Location
    United Kingdom
    Posts
    702
    Rep Power
    205
    Oh yes, I'm going to use it. Quite a simple idea to implement like you said.

    I'm just saying I won't take full advantage of it, I can see the advantages a guest customer would have in a bigger system.

    Originally Posted by JClasen
    Why? A guest user would mean an additional six lines of code for a derived class. (if even). Otherwhise you could only set your member as null. Unfortunately this'll mean lots of tests for your member to actually be an instance of "customer" or errors on about every call to a method of your non-object, if you leave out these tests..
    PHP Code:
    if($Tiredness TIREDNESS_MAX$CupOfTea++; 
    If you found what I've said helpful, I'm interested in reputation points!

IMN logo majestic logo threadwatch logo seochat tools logo