My php study notes (graduation project)

Source: Internet
Author: User
It is not only for graduation design, but also for the purpose of learning it and getting a website or something. as long as the website can be done well, I think it is easy to learn and try the php syntax, the application is also very good, and the class library is powerful, it can indeed write a very powerful server side. For me who only need small-function servers, it would be better.
Simply learning php, I think it is better to read the manual. It took a few days to look at the syntax. because of the programming Foundation, it seems faster now. I just wrote a simple server in php. of course, it is intended to support the client of a ticket booking system. Below are my notes on the learning process. There will be a review later.
When no class object exists, you can call methods in a class by using the scope identifier;
When accessing methods in the base class, you can write parent: method ();
Serialize () returns a string containing the byte stream representation of any value stored in PHP.
Unserialize () can be used to reconstruct the original variable value.
Serialization is used to save the object and save all the variables in the object. The functions in the object will not be saved, but only the class name.
When serializing and deserializing the same object, you can use the definition file method containing the same object.
This is because "new" does not return a reference by default, but returns a copy.
Php5
Class and object features:
Visibility: visibility
Attribute access limit: public: this attribute can be accessed anywhere,
This attribute can be accessed by the protect derived class or parent class, or any item in the class that defines this attribute)
Private: only the class can be accessed.
A member declared as static can not be accessed
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, the member cannot be accessed by the instantiated object,
Static members cannot be redefined in subclass ).
The static definition must be after the access attribute, for example, protect static
Static methods can be called without instantiation. Therefore, the $ this parameter cannot be included in static methods.
Static members cannot be accessed using->.
Constant: constant keyword. const is used to define unchangeable constants. $ is not required for definition.
The definition method is generally: const aconstant = 'constant ';
Variables defined by gloabl in php are used throughout the page, including the pages included by require and included pages.
Abstract class:
Abstract classes cannot be instantiated. any class with abstract methods must be defined as abstract classes.
If the abstract class is inherited, any abstract method in the abstract class must be rewritten. The access limit of these methods can only be
The access limit is the same or lower than that of the abstract parent class.
Abstract classes and abstract methods both use abstract as keywords.
Object interface)
The object interface allows you to specify which methods must be implemented, rather than letting you define which methods are captured.
The object interface is defined using the interface keyword. It is a standard class, but its methods are not implemented.
Any method in the interface object must be public, which is required by the interface object.
The implements label must be used to implement an interface. Therefore, the interface method must be implemented in a class. A class can implement multiple interfaces.
Overload:
Iterator:
The iterator can be a member of all public objects in the iterator class.
Implement the iterator interface in PHP5, which allows you to define how objects are accessed by iteration.
Design Mode:
The design pattern provides a good framework to implement some functional organization.
Factory mode: instantiate a required object during running.
Single-profit mode: The most obvious example is the database connection object. The following is an example of the best Singleton mode:
Singleton Function

The code is as follows:


   Class Example
{
// Hold an instance of the class
Private static $ instance;
// A private constructor; prevents direct creation of object
Private function _ construct ()
{
Echo 'I am constructed ';
}
// The singleton method
Public static function singleton ()
{
If (! Isset (self: $ instance )){
$ C = _ CLASS __;
Self: $ instance = new $ c;
}
Return self: $ instance;
}
// Example method
Public function bark ()
{
Echo 'Woof! ';
}
// Prevent users to clone the instance
Public function _ clone ()
{
Trigger_error ('Clone is not allowed. ', E_USER_ERROR );
}
}


You can also implement the iteratoraggregate interface object in php5 to define your own iteration method.
Magic functions:
The function names _ construct, _ destruct (see Constructors and Destructors ),
_ Call, _ get, _ set, _ isset, _ unset (see Overloading), _ sleep, _ wakeup,
_ ToString, _ clone and _ autoload are magical in PHP classes.
These functions exist in every php class. Do not use _ to define a function unless you really want it to have a magic function.
_ Tostring () function, which determines what happens when an object is converted to a character.
Final Keywords:
The final keyword is used to prevent the class or method declared by the final keyword from being inherited and overwritten.
Mandatory parameter type:
You can add a class name before a parameter to control the input parameter type.
Require () and include () are identical in all aspects except how to handle failures.
Include () generates a warning and require () causes a fatal error.
In other words, if you want to stop processing the page when the file is lost, do not hesitate to use require.
The require_once () statement contains and runs the specified file during script execution.
This action is similar to the require () statement,
The only difference is that if the code in this file has been included,
It will not be included again. For how this statement works, see The require () documentation.
PHP has a type operator: instanceof. Instanceof is used to determine whether a given object comes from a specified object class.
Sample code:

The code is as follows:


Class {}
Class B {}
$ Thing = new;
If ($ thing instanceof ){
Echo 'A ';
}
If ($ thing instanceof B ){
Echo 'B ';
}
?>


The PHP code segment end mark can be avoided. in some cases, when the output buffer and
It is better to omit include () or require.
This is not the case with include (). The script will continue to run. Make sure that the appropriate include_path is set.
_ CLASS _: Indicates the current CLASS.
Exception handling, extended exception handling class exception as needed
The require () statement contains and runs the specified file;

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.