Use cases of PHP static and non-static methods
Static Member
Class members are static members. you can directly use the class name + static member name to access this static member. because the static member exists in the memory, non-static members need to be instantiated to allocate the memory, therefore, static methods cannot access non-static members. because static members exist in the memory, non-static methods can directly merge static members in the class.
Non-static members
All non-Static members are non-Static members. after the class is instantiated, it can be accessed by the instantiated class name .. the lifetime of a non-static member is determined by the lifetime of the object .. static members do not have the concept of survival, because static members always reside in the content.
Class user {private static $ count = 0; public function _ construct () {self ::$ count = self ::$ count + 1;} public function getCount () {return self ::$ count;} public function _ destruct () {self ::$ count = self ::$ count-1 ;}} $ user1 = new user (); $ user2 = new user (); $ user3 = new user (); echo $ user1-> getCount (); echo ""; unset ($ user3); echo $ user1-> getCount ();