Introduction: This is a PHP learning note ------ [common keyword and magic methods in PHP object-oriented] detailed page, describes the knowledge, skills, and experience related to PhP, and some PHP source code.
Class = 'pingjiaf' frameborder = '0' src = 'HTTP: // biancheng.dnbc?info/pingjia.php? Id = 338759 'rolling = 'no'>
<? PHP/** common keywords in PHP ** final * 1. final cannot modify member attributes (constants in the class are not used as the key) ** 2. final can only modify classes and Methods **: * classes modified using final cannot inherit from quilt classes. ** Methods modified using final cannot overwrite quilt classes. ** this is used to restrict classes from being inherited, method does not overwrite ** static * 1. you can use static to modify member attributes and member methods, but not ** 2. the member attributes modified with static can be shared by all objects of the same class. ** 3. static data is data segments in memory (initialized static segments) ** 4. static data is allocated to the memory when the class is loaded for the first time, and will be directly obtained from the data segment when the class is used. ** 5. what is a class loaded? As long Program Use this class in ** Note: All static members must use the class name for access, without creating an object or accessing an object * Class Name :: static member ** if you use static members in the class, you can use self to represent the class name * Self: static member ** 6. static Method (static modification), cannot access non-static members * because non-static members, they must be accessed using objects, access to internal members uses the $ this * static method, which cannot be called by objects, and no objects exist. $ this does not represent any objects, non-static members must also use objects. * If a method does not use non-static members, you can declare it as a static method. * const ** 1. only member attributes can be modified ** 2. normal declared constant: Define ('constant name', 'testesttest'); ** 3. declare constants in the class using const ** 4. the naming method is the same as define ** 5. access Method and static member attributes (Use the Class Name: constant outside the class, and use the self: constant inside the class) ** 6. when declaring a constant, you must give the initial value ** the common magic method ** _ call () ** in PHP: an error occurs when a method does not exist in the called object, and the program exits. ** When to call: it will be automatically called when a method does not exist in an object is called ** This method requires two parameters ** _ tostring () ** it is automatically called when an object reference is directly output. It is the most convenient way to quickly obtain the string representation of an object. ** Object serialization (serialization ): convert an object into a binary string * 1. used to store objects in a database or file for a long time * 2. when an object is transmitted in multiple PHP files * serialize (): the parameter is an object, and the returned result is the string-based binary string * unserialize: the parameter is the binary string of the object, the returned object ** _ sleep () * is a method automatically called during serialization. ** function: serializes an object partially (serialized) * As long as an array is returned in this method, the array contains several member attributes ** _ wakeup () * The method automatically called in deserialization ** is a process of re-emergence of an object (_ construct () ,__ Cl One () ,__ wakeup () *** _ autoload () * Note: other magic methods are added to the class, this is the only method not added in the class * as long as a class is used on the page, the class name will be automatically passed to this parameter as long as the class name is used ** _ clone () * use _ clone to clone the cloned object ** original (original object) ** copy (Copied object ** _ clone () it is the function of the method automatically called when the object is cloned **: ** as long as an object is generated, initialization actions are required, which is similar to the function of the constructor * In _ clone () the $ this keyword in the method represents the copy object. $ that represents the original object *****/class person {var $ name; var $ age; vaR $ sex; const host = "localhost"; // declare the constant var static $ Country = "Chi Na "; // use static, static member attributes function _ construct ($ name, $ age, $ sex) {$ this-> name = $ name; $ this-> age = $ age; $ this-> sex = $ sex; echo "###############";} // static method static function test () {echo "test <br>";} function _ call ($ methodname, $ ARGs) {echo "called method {$ methodname} (parameter:"; print_r ($ ARGs); echo ") does not exist";} function _ tostring () {return "{$ this-> name} 1111111111122222 <br>" ;}// function _ clone () is automatically called when an object is cloned () {$ this-> name = "copy ";}/ /This method cannot overwrite final public function say () {echo "my name: {$ this-> name}, my age {$ this-> Age }:, my gender: {$ this-> sex} <br/> ";}protected function eat () {echo" wwwwwwwwwwwwwwwwwww <br> ";}function run () {echo self: host; // internal class access constant} protected $ nameprotected $ age; protected $ sex;} class student extends person {var $ School; function _ construct ($ name, $ age, $ sex, $ School) {parent ::__ construct (); $ this-> school = $ school;} protected functio N say () {parent: Say (); echo "my school {$ this-> school} <br/>" ;}function Study () {echo "{$ this-> name} is learning <br/>" ;}} echo person: $ country; // access the static member echo person: host; // external access constant $ P = new person (); echo $ P; // automatically calls _ tostring () $ p1 = clone $ P; // clone/_ autoload use function _ autoload ($ classname) {// This function is called every time a class name is used, and the class name is passed to the parameter include ". /". $ classname. ". class. PHP ";}?>
Love J2EE follow Java Michael Jackson video station JSON online tools
Http://biancheng.dnbcw.info/php/338759.html pageno: 8.