Pristine Series PHP Essentials

Source: Internet
Author: User
Tags autoload

What you need to remember and master about PHP collation

1./**/--------------------------------------------------------------------------------1./* Language Structure * *
Eval The () function calculates the string in PHP code, which must be a valid PHP code and must end with a semicolon (see http://www.w3school.com.cn/php/func_misc_eval.asp)

2./* Capitalization problem */-------------------------------------------------------------------------------2. /* Capitalization problem */-class name, method name, property name, function name: case-insensitive-variable name, constant name, element subscript: case-sensitive

3./* variable function */----------------------------------------------------------------------------------3./* variable function */get_ Defined_vars    //Returns an array of all defined variables (including environment variables, server variables, and user-defined variables)

4./* constant Correlation function */-------------------------------------------------------------------------------4./* constant Correlation function */ Definedget_defined_constants

Use of the 5./* String */-------------------------------------------------------------------------------the use of the 5./* string */ A string can be used as a collection of characters, and each character can be accessed independently. Applies only to single-byte characters (letters, numbers, half-width punctuation marks), such as Chinese, etc. not available $str = "ABCD"; echo $str [3];   Decho $str {0};   A

6./* "function" */----------------------------------------------------------------------------------6./* "function" */1) The declaration of a function is at compile time, so the definition is called again, and the definition and the call have no relation! 2) The file is just the carrier of the code, the program is executed in memory! 3) If the definition of the function is within the file that needs to be loaded, you need to load the file first, otherwise the call will be wrong! 4) The definition of a function can appear in other code snippets, when the function is not executed at compile time until it is executed until it is defined!    Only independent definitions will be compiled in memory! If it appears in another function body, it needs to be called when the outer function is defined and takes effect!    5) The function name is not case-sensitive 6) does not allow duplicate names, including system functions 7) "Variable function" function name can be substituted with other variables $func _name = "SayHello";       $func _name (); Call the SayHello () function at this point: the variable can only be used when called, not allowed when defined! 8) variables can be called functions as function names, as well as array element values!    9) The formal parameter parameter, the actual parameter argument can pass NULL to the parameter, indicates that the formal parameter does not want to pass the value shape participates in the argument between the value to pass, also can refer to pass.        Referring to passing parameters, you should precede the formal parameter with the & symbol when defining the function, and the call to the function argument must be how the variable chooses which delivery method to use?            A. Need to ensure the integrity of the original data B. Need for increased efficiency C. Pass-through for big Data Save memory 10) parameter default value A. The default value of a function's parameter must be a determined value, not a variable! As long as you define the constant before the call, you can use a constant as the default value for the parameter B. The default value of the function can be more than one, it is recommended that a parameter with a default value in the last face of the parameter list so that you can call the function, do not give the default value of the parameter value, otherwise error C.        Arguments can be non-scalar types, such as arrays, NULL D. Any default parameter must be placed on the right side of any non-default parameter 11) number of parameters a. The number of formal parameters is more than the number of arguments report warning level errors and null instead of B. Arguments more than formal parameters Do not reportError, parameter assignment C. Indeterminate number of parameters 1) A formal parameter is not defined, is always the argument more than the formal parameter 2) "Variable quantity parameter" Func_get_args () gets the value of all arguments when the current function is invoked, returns a An array of all the argument values Func_get_arg () Gets the value of an argument, identified by an index value, e.g:func_get_arg (0) Func_num_args () Gets the number of all arguments 12) "return    The return value A. function has only one return value, you can get similar results by returning an array, but you can have multiple return statements B. The return statement immediately aborts the function and returns control back to the line of code that called the function. can return any type that includes arrays and objects            D. Return of function also score pass and reference pass (returns a variable only) 1) The default is the value passing way 2) The reference is passed:-When the function is defined, the function name is preceded by A & to indicate that the function can return a reference            -When a function is called, the function name is preceded by A & that represents the reference to the return of the function. At this point, modifying the return value outside the function modifies the value of the return variable within the function-if the function needs to return a reference, you need to return a variable to                -Returns a reference from a function that must use the reference operator & function &returns_reference () {return $someref when the function declares and assigns a return value to a variable;}        $newref =& returns_reference (); 3) Return the role of the reference




7./* "Database Operations" */---------------------------------------------------------------------------7. /* "Database Operation" */#连接认证mysql_connect        Connect and certify database # Send SQL statement, receive execution result mysql_query            Send SQL statement        only to select, show, explain, Describe statement execution successfully returns a resource identifier, and other statements successfully return TRUE. Execution failure returns false. #处理结果mysql_fetch_assoc    fetch a row from the result set as an associative array        , retrieving only one entry at a time, similar to the    record pointer in each result set mysql_fetch_row        Take a row from the result set as an enumerated array mysql_fetch_array    gets a row from the result set as an associative array, or as an array of numbers, or both with an array    mysql_fetch_array (Resource $result [, int $ result_type  ]) optional    parameter Result_type optional values are: Mysql_assoc,mysql_num and Mysql_both (default) Mysql_free_result    Release result memory # Close link mysql_close            close connection




8./* Automatically load objects */------------------------------------------------------------------------------8. /* Automatically load objects */
-Automatically invoke the __autoload function when trying to use a class that has not yet been defined-automatically load the used class name file (depending on the name of the class name), so the class name matches the class file name-each file that needs to load the class needs to have the __autoload function-will __ The AutoLoad function writes to a separate file, each file that needs to be used for the class require the function file-the __autoload parameter is the class name function __autoload ($class _name) {require_once $_server[ "Document_root"].    "/class/$class _name.php";} $_server["Document_root"] the document root directory where the script is currently running-you can deduce the name of the class by the class name! -If there is more than one auto-loading function for an item, define a normal function that can be loaded, and register the function with Spl_autoload_register before the function. # spl_autoload_register-Register __autoload () function bool Spl_autoload_register ([callback $autoload _function])-You can register multiple auto-load functions, First registration-Once the auto-load function is registered, the __autoload is invalidated. -When registering a function, the parameter is the function name (note the quotation marks); When you register a method, the parameter is an array of methods for the method of registering the class or object as an array: Spl_autoload_register (Array (__class__, ' __autoload ')) __CLASS__ represents the current class name, if the object is available $this, see the manual 



9./* Magic method */-------------------------------------------------- ---------------------------------9. /* Magic method */
 __construct Constructor Method __destruct destructor __clone Clone object __sleep serialized object __wakeup Deserialize Object __a Utoload automatically loaded, using a class but not found when the __tostring object is used as a string __invoke when attempting to invoke an object as a function call 

 10./* Reload overload*/---------------------------------------------------------------------------10./* Reload Overload*/refers to dynamically "create" class properties and methods the user is free to add additional properties to the object, which is overloaded. All overloaded methods must be declared public. Overloaded methods are called when a class property or method is called that is undefined or not visible under the current environment. Parameters for overloaded related magic methods cannot be passed by reference. # Property overloading-handling an inaccessible property property overload can only be done in the object. # property Overloading is not valid for static properties in static methods, these magic methods will not be called. So none of these methods can be declared static. __set public void __set (string $name, mixed $value) when assigning a value to an inaccessible property: bulk management of private properties, indirect protection of object structure __get reading values of inaccessible properties When public mixed __get (string $name) __isset when isset () or empty () is called on an inaccessible property, the public bool __isset (string $name) __unse t when you call unset () on an inaccessible property, the public void __unset (string $name) # method overload-handles an inaccessible method __call when an inaccessible non-static method is called (such as undefined, or        Mixed __call (string $name, array $arguments) __callstatic is called automatically when an inaccessible static method (such as undefined or invisible) is called public static mixed __callstatic (string $name, array $arguments) # $name parameter is the name of the method to invoke. The $arguments parameter is an array that contains the arguments to pass to the method. 


11./* "Class-to-Object related functions" */--------------------------------------------------------------------11./* "class-to-object related functions" */class_ Alias ([$original [, $alias]])  gives the class an alias class_exists ($class [, $autoload]) to   check whether the class is defined interface_exists ($interface [ , $autoload]) to   check if the interface has been defined method_exists ($obj, $method) Check if the method of the class exists property_exists ($class, $property)  Checks whether an object or class has this property get_declared_classes (void)  returns an array of the names of the defined classes get_declared_interfaces (void)   Returns an array containing all declared interfaces Get_class ([$obj])       The class name of the returned object Get_parent_class ([$obj])    returns the parent class name of the object or class Get_class_methods ($class) Returns   an array of the method names of the class Get_object_vars ($obj)   returns an associative array of object Properties Get_class_vars ($class)  returns an array is_a ($obj, which consists of the default properties of the class. $class) returns trueis_subclass_of ($obj, $class) if the object belongs to the class or if the class is the parent class    of this object Trueget_object_vars ($obj) If this object is a subclass of the class   returns an associative array consisting of object properties

Pristine Series PHP Essentials

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.