Phpstorm IDE
Development font Selection: Source Code Pro, Courier New, Concolas
php Namespaces: Resolves conflicts of the same name method in different classes
namespace Test1;
function Test () {
}
Auto-loading:
function __autoload ($class) {
Require __dir__. ' /' $class. ' PHP ';
}
Spl_autoload_register (); This function allows multiple autoload to be present in the first line
For example:
Spl_autoload_register (' Autoload1 ');
Spl_autoload_register (' autoload2 ');
function Autoload1 ($class) {
Require __dir__. ' /' $class. ' PHP ';
}
function Autoload2 ($class) {
Require __dir__. ' /' $class. ' PHP ';
}
Require after class Name:: Method name Call ();
For example: Test1::test (); Test2::test ();
PSR-0 specification
1 The namespace of PHP must be identical to the absolute path
2 The first letter of a class name consistent with the file name must be capitalized
3 In addition to the intersection file, the other ". PHP" must have only one class that cannot have executable code such as: Echo ();
__dir__ Magic constant Gets the path to the current file
__function__ Magic Constants Get Current method
__method__ Magic constant Gets the current class name and method
BASEDIR Web site root directory
Introduction to SPL Standards
Splstack (); Advanced post-Outbound data structure
$stack =new splstack ();
$stack->push ("test1"); Enter the station first
$stack->push ("test2"); Advanced
echo $stack->pop (); Back out of the station Test2
echo $stack->pop (); Back out Test1
Splqueue (); FIFO queue-type data structure
$SplQueue =new splqueue ();
$SplQueue->enqueue ("test1"); Advanced
$SplQueue->enqueue ("test2"); Advanced
echo $SplQueue->dequeue (); First out test1.
echo $SplQueue->dequeue (); First out test2.
Splminheap (); Heap-structured data structures
$SplMinheap =new splminheap ();
$SplMinheap->insert (' test1 ');
$SplMinheap->insert (' test2 ');
echo $SplMinheap->extract (); Test1
echo $SplMinheap->extract (); Test2
$sqlFixedArray (); Fixed-size arrays (fixed lengths)
$array = new $sqlFixedArray (10); (Set data length in parentheses)
$array [' 0 ']=1;
$array [' 8 ']=8;
The advantage of the PHP chain test is that you can implement many functions with one line of code.
$ob->where ()->order ()->limit ()->select ();
PHP Object-oriented advanced features
Use of the PHP magic method
1 __get/__set//Take over the object's first letter
2 __call/__callstatic//static method call to control the method call/control class for PHP
3 __tostring//Convert a PHP object to a string
4 __invoke//use PHP as a function
Prints out the result is no matter subscript 1-7 has no value will print out no value automatically give a null value
Phpstorm Configuration Installation
http://blog.csdn.net/ikscher/article/details/43672365
Three basic design Patterns
Factory mode: A factory method or class to generate a pair of images rather than a direct new in the code instead of new
The advantage: In the event of a change, only one Factory mode class can be changed.
Singleton mode: Allows an object of a class to be created only once
Benefit: Regardless of how many instance objects are actually connected to the database only once
Registration mode: Global shared Swap object is better with Factory mode
Benefit: Global shared swap objects
Registering a tree with a factory model can reduce the waste of memory resources. Because the same object is called. You can also add data to
Like mapping mode reduces the direct operation of the database on the properties of the class library
Adapter mode
To encapsulate different interfaces into a unified API
PHP class is a single inheritance, that is, do not support multiple inheritance, when a class requires multiple classes of functionality, inheritance is powerless, for this reason PHP
into the interface technology of the class.
If all the methods inside an abstract class are abstract, and no variables are declared, and all members of the interface are public
Permission, then this particular abstract class is called an interface.
The interface is defined using the keyword interface, and the method in the interface is implemented using the keyword implements, and must be fully implemented.
The policy pattern encapsulates a specific set of behaviors and algorithms into classes to accommodate certain context contexts, which are policy patterns
For example, to determine the user's gender to give different needs
First write the man's needs and then write the woman's needs.
Depending on the value of the transfer to call that demand and no longer use tedious judgment to implement the change, just write one more requirement.
Data Object Mapping mode
1 The Data Object mapping pattern is the mapping of objects and data stores, and operations on an object are mapped to operations on data storage
Observer mode when an object state changes, the objects that depend on it are all notified and automatically updated for use when an event is sent
When they are born, they can be written in the Observer class.
The prototype pattern is similar to the Factory mode, which is used to create objects
Unlike the implementation of the factory pattern, the prototype pattern is to create a good one prototype object beforehand, and then create a new object from the Clone prototype object.
This eliminates the initialization operation at class creation time
Prototype mode is suitable for the creation of large objects. Creating a large object requires a lot of overhead, and if new is expensive every time, prototype mode only
A memory copy is required.
Useful: For example, a class object that is created involves a lot of loops, and so on, when the next call to new is made, the object is cloned directly.
Instead of continuing new
Decorator mode adorner mode (Decorator), which can dynamically add the ability to modify a class provides a feature that, if modified
and added additional functionality to the traditional editing mode, which requires writing a subclass to inherit it and re-implement the class method
With adorner mode, you can achieve maximum flexibility by simply adding an adorner object at run time.
The iterator pattern iterates through the inner elements of an aggregated object without needing to know the internal implementation
In contrast to traditional programming patterns, the iterator pattern can hide the operations required to traverse elements
<?php
namespace test;
Class AllUser implements \iterator {//Call Iterator interface provided by PHP itself
protected $ids;
Protected $data = Array ();
protected $num;
function __construct () {
Instantiating a model
Read database
}
function valid () {//Verify that there is currently the next element
}
function Next () {//Get the next element
}
function current () {//Gets the present element
}
Function Rewind () {//Reset entire iterator
}
Function key () {//Gets the position in the iterator
}
}
Proxy mode
A proxy object is established between the client and the entity, and the client operations on the entity are delegated to the proxy object, and the entity is hidden
Specific implementation details of the
Proxies can also be detached from business code, deployed to additional servers, and delegated by RPC in business code.
404 interface
Http://www.html5cn.org/article-8131-1.html
This article is from the "Long Gray Corner" blog, please be sure to keep this source http://bamilk.blog.51cto.com/10785704/1702550
Learn Small notes---Big talk PHP design mode