PHP has simple syntax, very good applications, and powerful class libraries. It can indeed write a very powerful server side. For someone like me who just needs a small server, it couldn't be better.
Simply speaking, when it comes to learning PHP, I think it’s better to read the manual. I spent a few days looking at the syntax. Because I have a programming foundation, it seems to be faster now. I just finished writing a simple server in PHP, for a purpose of course, to support the client of a ticket booking system. Below are my notes on the learning process. It would be nice to have a review in the future.
When there is no object of a certain class, you can call a method in a certain class through the scope discriminator (::);
When accessing a method in a base class, you can write parent::method() ;
serialize() returns a string containing a byte stream representation of any value that can be stored in PHP.
unserialize() can use this string to reconstruct the original variable value.
Using serialization to save objects can save all variables in the object. The functions in the object are not saved, only the name of the class.
When serializing and deserializing the same object, you can use the definition file method that contains the same object.
This is because "new" does not return a reference by default, but returns a copy.
php5
Characteristics of classes and objects:
visibility: visibility
Attribute access limits: public: This attribute can be accessed anywhere,
protect derived classes or parent classes can access to this attribute, or an item within any class that defines this attribute)
private: only accessible within the class
A member declared as static can not be accessed with
an instantiated class object (though a static method can).
Static members and methods cannot be re-defined in subclasses.
(If a member is defined as static, then the member cannot be accessed by the instantiated object,
Static members cannot redefined in subclasses).
Static definition must be after accessing properties, such as: protect static
Static methods can be called without instantiation, so the $this parameter cannot be used when using static methods.
Static members cannot be accessed using ->.
constant: constant keyword, const is used to define immutable constants, and there is no need to use the $ symbol when defining.
The definition method is generally: const aconstant = 'constant';
The variables defined by glob in php are used throughout the page, including pages included in require and pages included in include.
Abstract class:
Abstract class cannot be instantiated. Any class with abstract methods must be defined as an abstract class.
If you inherit an abstract class, any abstract method in the abstract class must be overridden. The access limit of these methods can only be
the same as or lower than the access limit of the abstract parent class's methods.
Both abstract classes and abstract methods use abstract as the keyword.
Object interface (object interface)
Object interface allows you to specify which methods must be implemented, rather than letting you define which methods are captured.
Object interface is defined using the interface keyword. It is a standard class, but none of its methods are implemented.
Any method in an interface object must be public, which is what interface objects must follow.
To implement an interface, you must use the implements mark, so the interface method implementation must be in a class. A class can implement multiple interfaces.
Overloaded:
Iterator:
Iterator can access all public object members in the class.
Implement the iterator interface in PHP5, which allows you to define how objects are accessed iteratively.
Design pattern:
Design pattern provides a good framework to implement some functional organization.
Factory pattern: Instantiate a required object during runtime.
Simple interest mode: The most obvious example is: database connection object. The following is an example of the best singleton pattern:
Singleton Function