PHP experience, skills finishing (1)

zhaozj2021-02-16  60

Recent work is relatively busy, there are several projects to perform functional adjustments, and I have also studied a new OOP-based development architecture for the company. But I didn't forget to care about PHP, and there is time to go to Cu to irrigate, help answer some questions. Today I am going to see some of the PHP experience and skills in the near future.

I. Include and Require:

For some netizens who have just contacted PHPs, I feel puzzled with Require, I have recently received some questions about these two orders, so I will explain this. .

The features of including Require are very similar, and their roles are introduced into an external file. Flexible use of include and Requires can easily be better modular programming, such as we can put the functions you need on the site or some The public program part writes a separate PHP program that requires when the current program needs to be used, so we can avoid writing all the procedures together to the future maintenance work.

Here, I mainly explain the difference between INCLUDE and Require, for an Include ("Test.php") operation, only the code is parsed and executed when the program is executed to the include statement, and Require ("test.php") Then, the statement of Require ("Test.php") is replaced with the contents of Test.php in the pre-compiled phase of the PHP program.

When is INCLUDE, when do you use Require? My suggestion is that if the introduced external file call is frequent, use Require, because PHP can insert the specified file into the script in the previous stage of the reading code, and the execution speed is slightly faster. If the introduced external file is included in a control block (eg if, switch, etc.), because if you use Require, even if your program does not need to introduce files according to IF, it is still pre-compiled again. Replace the Require statement with the file content.

Supplementary description: INCLUDE_ONCE and include, request_once are similar to the request command. The only difference is that inlCude_once and request_once are only incorporated once, if the file has been introduced if the file has been introduced, it will no longer be introduced.

Second, the constructor of inheritance in PHP4:

The constructor will be executed when the entity of the class is defined. If class A inherits class B, both classes have their own constructor, then which constructor is automatically executed when the entity defines the entity of class A.? Let's take two examples:

Routine: 1

The execution result of the program is displayed: foo1, so the constructor of class A is automatically executed, and the constructor of class B inherited by class A does not execute, we take the constructor of class A to take a test:

Routines: 2 The execution result is displayed: foo, this The constructor of the class B inherited by the class A is automatically executed, so summarizes the following: When a class has its own constructor, it will be automatically executed, otherwise the structural function of the class it inherits will be automatically executed.

Third, two uncomfortable attention but really use PHP functions:

Print_r () Print_R function can output an array structure: for example: $ a [0] = 1; $ a [1] = 2; $ a [2] = array ('a' => 'a', 'b' => 'b'); Print_R ($ A); execution result will be displayed: array ([0] => 1 [1] => 2 [2] => Array ([A] => a [b] => b) In actual programming, because the Print_R function can help easily observe a number and key name, key value, etc., so much convenience can be given when debugging. VAR_EXPORT () var_export function outputs or returns a string representation of a variable; for example: $ a [0] = 1; $ a [1] = 2; $ a [2] = array ('a' => 'a', 'b' => 'b'; var_export ($ a); execution result will be displayed: array (0 => 1, 1 => 2, 2 => array ('a' => 'A', ' B '=>' b ',),). Obviously, this is a complete definition of array variables. In actual programming, we can generate a set of var_export functions in a structural saving file that is defined. This saved file is filed after INCLUDE, we will directly get a variable that can be used, which is more than putting data in text , Read analysis is much easier to get a set of variables. E.g:

'a', 'b' => 'b'); $ content = "< ? / r / n / $ a = ".var_export ($ a, true)." / r / n?> "; $ fp = fopen (" a.php "," w "); flock ($ fp, lock_ex Fwrite ($ FP, $ Content); Flock ($ fp, lock_un); fclose ($ fp);?>

In the future, we can obtain an array variable of $ A, in this case, the parameter true of the var_export ($ A, TRUE) indicates that the result of var_export is returned without outputting the display. Posted at 13:38:44 on 05/18/04 by

Arnold - 94 Views - Category:

PHP

Comments

Can you add a link? I like your blog very much.

Posted by

Vidar, 05/20/04 19:07:52

Ok, how much is your website name and address?

Posted by

Arnold, 05/21/04 11:14:13

Forever PHP

http://www.phpchina.org/blo ...

I have added you, I am also the top of Cu, ID called Vidarz

Posted by

Vidar, 05/21/04 18:47:51

Require ("Test.php") is replaced with Test.php in the pre-compiled phase of the PHP program when the program is executed to the include statement. Scriptures.

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

Not like this, look at the manual:

.

Note: Prior to PHP 4.0.2, the following applies: require () will always attempt to read the target file, even if the line it's on never executes The conditional statement will not affect require () However, if the line.. on which the require () occurs is not executed, neither will any of the code in the target file be executed. Similarly, looping structures do not affect the behaviour of require (). Although the code contained in the target file is still subject to The loop, The Require () Itself Happens Only Once.

转载请注明原文地址:https://www.9cbs.com/read-18160.html

New Post(0)