* ********** Bygarcon1986 ************************ 1. $ this variable is a reference to the current object, $ this-var; $ this-method (); 2. in php5, variables and constants are called property and functions are called method. declared attribute: invalidpublic $ Varel. lo; public $ var2EODhelloEOD; public
/*********** By garcon1986 ***********************/1. $ this variable is a reference to the current object, $ this-var; $ this-method (); 2. in php5, variables and constants are called property and functions are called method. declare attributes: // invalid public $ var = 'hel '. 'lo'; public $ var2 = EOD hello EOD; public
/*********** By garcon1986 *******************/
1. $ this variable is a reference to the current object, $ this-> var; $ this-> method ();
2. Variables and constants in php5 are called property and functions are called method.
Declared attributes:
// Invalid
Public $ var = 'hel'. 'lo ';
Public $ var2 = <
Hello
EOD;
Public $ var3 = 1 + 2;
Public $ var4 = self: StaticMethod ();
Public $ var5 = $ myvar;
// Valid
Public $ var6 = myConstant;
Public $ var7 = array (true, false );
Public $ var8 = <'eod'
Hello
EOD;
3. inheritance: Use extends
Class {
Function (){
}
}
Class B extends {
Function B (){
}
}
4. parent: access methods or attributes in the parent class
5. You can access static attributes or methods without instantiating classes.
Self: static variables used to access this class.
Static attributes cannot be accessed in the instantiated class object, but static methods can be accessed.
Static attributes cannot be accessed.
If you call a non-static method statically, an E_STRICT warning is triggered.
Example:
Class Foo
{
Public static $ my_static = 'foo ';
Public function staticValue (){
Return self: $ my_static;
}
}
Class Bar extends Foo
{
Public function fooStatic (){
Return parent: $ my_static;
}
}
Print Foo: $ my_static. "/n ";
$ Foo = new Foo ();
Print $ foo-> staticValue (). "/n ";
Print $ foo-> my_static. "/n"; // Undefined "Property" my_static
Print $ foo: $ my_static. "/n ";
$ Classname = 'foo ';
Print $ classname: $ my_static. "/n"; // As of PHP 5.3.0
Print Bar: $ my_static. "/n ";
$ Bar = new Bar ();
Print $ bar-> fooStatic (). "/n ";
?>
6. Define-defines a constant with a name.
Define ("CONSTANT", "hello world ");
Echo CONSTANT; // output hello world
Echo Constant; // output "Constant" and issues a notice.
Define ("GREETING", "Hello you.", true );
Echo GREETING; // outputs "Hello you ."
Echo Greeting; // outputs "Hello you ."
True will make letters insensitive, and false will make characters sensitive. The default value is character-sensitive, that is, false.
7. defined () is used to verify whether a constant exists.
If (defined ('constant ')){
Echo CONSTANT; // output "hello world"
}
8. const is used to declare constants;
$; Is not required for constants;
The constant value must be a constant expression, not a variable, attribute, arithmetic expression, or function.
For example, const constant1 = "test of contant ";
9. constant () is used to obtain the constant value.
Define ("mx", 100 );
Echo mx;
Echo constant ("mx ");
10. _ autoload ():
Test1:
Function _ autoload ($ class_name ){
Require_once $ class_name. '. php ';
}
$ Obj = new huanhang;
Test2:
Function _ autoload ($ class_name ){
Require_once $ class_name. '. php ';
}
Class huanhang {
Function huanghang (){
Echo "huanhang sleep ";
}
}
$ Obj = new huanhang ();
$ Obj-> huanghang ();
11. _ construct
_ Construct constructor: This method is called when an object is created. The advantage of this method is that the constructor has a unique name regardless of the name of the class it belongs.
So you don't need to change the name of the constructor when changing the class name.
_ Destruct destructor. PHP will call this method before the object is destroyed (that is, before it is cleared from memory ).
12. abstract: abstract classes and abstract methods are introduced in PHP5.
Abstract classes cannot be instantiated.
Any class contains more than one abstract method. This class must also be declared as an abstract class.
When an abstract class is inherited, all abstract methods in the parent class must be defined in the subclass, and the visibility of these methods must be consistent with the methods of the parent class or have fewer restrictions. For example
If the method is protected, the subclass method must be protected or public.
13. interface:
The interface is defined by the interface keyword, but the methods do not need to be defined.
All methods in the interface must be public
All methods must implement implemented in the class; otherwise, a serious error may occur.
A class cannot implement two interfaces, because it may cause confusion.
The interface can also be inherited through extends
14. visibility
The attributes of the class include public, protected, and private. The var definition is equivalent to public.
Class methods include public, protected, and private. The default value is public.
15. overloading: dynamically creates class attributes and methods. Implemented by magic functions.
All overload methods must be declared as public.
PHP5 provides an iteration object function. Just like using an array, you can use foreach to traverse the attributes of an object. By default, external iterations can only
Obtain the value of the externally visible attribute.
16. design pattern design Mode
Factory allows you to instantiate an object during code execution.
Singleton is used to generate a unique object for a class. The most common feature is database connection.
17. magic method)
_ Construct, _ destruct (see constructor and constructor), _ call, _ callStatic, _ get, _ set, _ isset, _ unset (see overload ),
_ Sleep, _ wakeup, _ toString, _ set_state, _ clone, and other methods are called Magic methods in PHP ).
PHP treats all class Methods Starting with _ (two underscores) as magic methods. Therefore, when you define your own class methods, do not use _ as the prefix.
18. Final
If the method in the parent class is declared as final, the subclass cannot overwrite the method;
If a class is declared as final, it cannot be inherited.
19. clone
$ Copy_of_object = clone $ object;