<? Php Class Student { // You have the permission to access attributes, methods, and functions in the class (functions and methods are the same concept) // Private protected public // The class constant does not have an access modifier Const STUDENT = 'Tom '; // Attributes Public $ stu_name; // Static attributes Public static $ stu_num = 1; // Method Public function stuFunction (){ Echo 'non _ static_function ',' <br/> '; } // Static method Public static function static_stuFunction (){ Echo 'static _ function', '<br/> '; } // Automatically called when the constructor creates an object Public function _ construct ($ stu_name ){ $ This-> stu_name = $ stu_name; Echo '_ construct', '<br/> '; } // The Destructor is automatically called when an object is destroyed. Public function _ destruct (){ Echo '_ destruct', '<br/> '; } } // Instantiate a Class Object $ Object = new Student ('Tom '); // Object call attributes Echo $ object-> stu_name, '<br/> '; // Static attributes of object calls Echo $ object: $ stu_num, '<br/> '; // Class call static attributes Echo Student: $ stu_num, '<br/> '; // Call methods and static methods respectively using objects $ Object-> stuFunction (); $ Object-> static_stuFunction (); $ Object: stuFunction (); $ Object: static_stuFunction (); // Use classes to call methods and static methods respectively Student: stuFunction (); Student: static_stuFunction (); // Class call class constant Echo Student: STUDENT, '<br/> '; |