My PHP Learning Notes (Graduation design) _php skills

Source: Internet
Author: User
Tags constant exception handling serialization visibility
The PHP syntax is simple, the application is very good, and the class library is powerful, it can write a very powerful server side. It would be a good thing for someone like me who only needs a small function server.
Simply speaking of learning PHP, I think it is better to read the manual. It took a few days to look at the grammar, because there was a programming base, so now it looks more quickly. Just finished using PHP to write a simple server, of course, there is a purpose, ready to support a booking system client. Here are my notes for the learning process. There is a review later.
When an object of a class does not exist, you can invoke the method in a class by the scope resolution (::);
Access to methods in the base class can be written as Parent::method ();
Serialize () returns a string containing the 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 save all variables in the object. The function in the object is not saved, only the name of the class.
Serialization and deserialization of the same object can be implemented using a 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
The access limit for a property: 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 attribute.
Private: Only classes within the class can access
A member declared as static can is accessed with
An instantiated class object (though a static method can).
The Static members and methods cannot are re-defined in subclasses.
(If a member is defined as static, then the member cannot be accessed by the instantiated object.
Static members cannot be redefined in subclasses.
The static definition must be after accessing the property, such as: Protect static
Static methods can not instantiate calls, so you cannot use static methods with $this parameters.
Static members cannot be accessed using->.
Constant: constant keyword, const is used to define immutable constants that do not need to be defined with the $ symbol.
The definition method is generally: const ACONSTANT = ' constant ';
GLOABL-defined variables in PHP are used throughout the page, including require included pages and include pages.
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. The access limits of these methods can only be
The same or lower access limits to the methods of the abstract parent class.
Abstract classes and abstract methods use abstract as a 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 by using the interface keyword. It is a standard class, but none of its methods have been implemented.
Any method in the 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 inside 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 the object is iterated over.
Design pattern:
Design patterns provide a good framework for implementing a number of functional organizations.
Factory mode: Instantiate a required object during the run process.
Simple mode: One of the most obvious examples is the database connection object. The following is the best example of a single example pattern:
Singleton Function
Copy Code code as follows:

<?php
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 iterative method.
Magic function:
The function names __construct, __destruct (for the constructors and destructors),
__call, __get, __set, __isset, __unset (= overloading), __sleep, __wakeup,
__tostring, __clone and __autoload are magical in PHP classes.
These functions exist in each of the PHP classes. You should not use __ to define functions unless you really want this function to have magic functionality.
__tostring () function, which will determine what happens when an object converts to a character.
Final key word:
The final keyword is used to prevent classes or methods that apply the final keyword declaration from being inherited and overwritten.
Parameter type coercion:
You can control the incoming parameter type with the class name class before the argument.
Require () and include () are exactly the same in all respects except how to handle failures.
Include () produces a warning and require () causes a fatal error.
In other words, if you want to stop processing the page when you lose the file, don't hesitate to use require ().
The require_once () statement contains and runs the specified file during the execution of the script.
This behavior is similar to the Require () statement,
The only difference is that if the code in the file is already contained,
is not included again. See the documentation for require () about how this statement works.
PHP has a type operator: instanceof. Instanceof is used to determine whether a given object is from a specified object class.
code example:
Copy Code code as follows:

<?php
Class A {}
Class B {}
$thing = new A;
if ($thing instanceof A) {
Echo ' A ';
}
if ($thing instanceof B) {
Echo ' B ';
}
?>

The PHP code snippet end tag can not, in some cases when using output buffering and
It is better to omit the include () or require ().
Include () is not the case, 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;

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.