My PHP Learning Notes (Graduation design) _php Tutorial

Source: Internet
Author: User
PHP syntax is simple, the application is very good, and the class library is powerful, it can really write a very powerful server side. It would be great for someone like me who only needs a small-function server.
Simply to learn PHP, I think it is good to read the manual. It took a few days to look at the grammar, because there was a programming foundation, so now it looks faster. Just finished using PHP to complete a simple server, of course, there is a purpose, ready to support a booking system for the client. Here are my notes on the learning process. There will be a review later.
When an object of a class does not exist, a method in a class can be called by a scope-resolved character (::).
Access to methods in the base class can be written as 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 an object can hold all the variables in the object. The function in the object is not saved, only the name of the class.
When serializing and deserializing the same object, it can be implemented using a definition file method that contains the same object.
This is because "new" does not return a reference by default and returns a copy.
PhP5
Characteristics of classes and objects:
Visibility: Visibility
Access limits for attributes: Public: This property can be accessed anywhere
Protect a derived class or parent class can access this property, or any item within a class that defines the property)
Private: Only within the class can access
A member declared as static can is accessed with
An instantiated class object (though a static method can).
Static members and methods cannot is re-defined in subclasses.
(If a member is defined as static, the member cannot be instantiated to access the object,
A static member cannot be redefined in a subclass).
The static definition must be accessed after the property, such as: Protect static
A static method can not instantiate a call, so a static method cannot be used with the $this parameter.
Static members cannot be accessed with.
Constant: constant keyword, const is used to define immutable constants, which are defined without the use of the $ symbol.
The general definition method is: const ACONSTANT = ' constant ';
Variables defined by GLOABL in PHP are used throughout the page, including the pages that require contains and the pages included in the include.
Abstract class:
An abstract class cannot be instantiated, and any class with an abstract method must be defined as an abstract class.
If you inherit an abstract class, any abstract method in the abstract class must override the implementation. Access limits for these methods can only be
The method with the abstract parent class has the same or lower access limit.
Both abstract and abstract methods use abstract as the keyword.
Objects interface (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 none of its methods are implemented.
Any method in an interface object must be public, which is what the interface object must follow.
Implementing an interface must be marked with implements, so the interface method implementation must be within a class. A class can implement multiple interfaces.
Overload:
Iterators:
Iterators can access all public object members within a class.
Implement the iterator interface inside the PHP5, which allows you to define how objects are accessed iteratively.
Design mode:
Design patterns provide a good framework for implementing some functional organizations.
Factory mode: Instantiates a required object during the run.
Simple interest Mode: The most obvious example is the database connection object. Here is an example of one of the best examples of singleton patterns:
Singleton Function
Copy CodeThe code is as follows:
   Class Example
{
Hold a 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 inside the PHP5 to define your own iterative methods.
Magic function:
The function names __construct, __destruct (see Constructors and destructors),
__call, __get, __set, __isset, __unset (see overloading), __sleep, __wakeup,
__tostring, __clone and __autoload is magical in PHP classes.
These functions exist in each of the PHP classes. You don't have to use __ to define functions unless you really want this function to have magic functionality.
__tostring () function, this function will determine what happens when an object is converted to a character.
Final keyword:
The final keyword is used to prevent classes or methods that are declared by applying the final keyword from being inherited and overwritten.
Parameter type coercion:
You can control the incoming parameter type by adding the class name class before the parameter.
Require () and include () are exactly the same in all respects except how to deal with failures.
The include () generates a warning and require () causes a fatal error.
In other words, if you want to stop processing a page when you lose a file, don't hesitate to use require ().
The require_once () statement contains and runs the specified file during script execution.
This behavior is similar to the Require () statement,
The only difference is if the code in the file is already contained,
is not included again. See the documentation for require () for how this statement works.
PHP has a type operator: instanceof. The instanceof is used to determine whether a given object is from a specified object class.
code example:
Copy CodeThe code is as follows:
Class A {}
Class B {}
$thing = new A;
if ($thing instanceof A) {
Echo ' A ';
}
if ($thing instanceof B) {
Echo ' B ';
}
?>

The PHP snippet end tag can not, in some cases when using output buffering and
It is better to omit the include () or require ().
The include () is not the case and the script will continue to run. Also be sure to set the appropriate include_path.
__class__: Refers to the current class.
Exception handling, extending exception handling classes as needed exception
The Require () statement contains and runs the specified file;

http://www.bkjia.com/PHPjc/325147.html www.bkjia.com true http://www.bkjia.com/PHPjc/325147.html techarticle PHP syntax is simple, the application is very good, and the class library is powerful, it can really write a very powerful server side. It would be great for someone like me who only needs a small-function server. Pure ...

  • 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.