Introduction: this is to use pear to write your next PHPProgram(Pan fan night sailer) (1) the details page describes PHP, related knowledge, skills, experience, and some PHP source code.
Class = 'pingjiaf' frameborder = '0' src = 'HTTP: // biancheng.dnbc?info/pingjia.php? Id = 323741 'rolling = 'no'>
This article from: http://www.cn.ibm.com/developerWorks/linux/sdk/php/pear1/index.shtml
Pan fan (night & nbsp; sailer) & nbsp; (nightsailer@hotmail.com)
Beijing Saidi Network Information Technology Co., Ltd.
2001 & nbsp; Year & nbsp; 6 & nbsp; month
You may already be a veteran of PHP, and write a lot of great stuff.Code. However, if you want to add them to your current
Is it difficult to go to the project? Your friend wants to use your code as a module in his project, but you find that
You have used a completely different encoding style, so it is better to rewrite it!
Please come with me and use the pear standard to compile your PHP program. Your program will be more dynamic, and your program and code will
It will be very convenient to integrate with the code of other experts, pear is like CPAN for Perl, it will make PHP produce higher performance
Quantity.
What is pear & nbsp;
Pear is the abbreviation of the PHP extension and application library (the & nbsp; PHP & nbsp; Extension & nbsp; and & nbsp; Application & nbsp; repository.
It is a code repository for PHP extensions and applications. In short, pear is the CPAN of PHP.
Why pear? & Nbsp;
PHP is a very good scripting language that is concise and efficient. With the release of 4.0, more and more people use it for dynamic
The development of websites can be said that PHP has become one of the best internet development languages.
PHP is the preferred language for website developers who develop small and medium-sized commercial applications quickly and efficiently. However, with the application of PHP
And lack of unified standards and effective management for these applications.CommunityIt's hard for people in the Perl community
In this way, code and applications can be easily shared, because PHP lacks a unified code library like CPAN to classify and manage application generations.
Code module (Everyone familiar with Perl knows that CPAN is a huge library of Perl extension modules.
In the appropriate category directory under CPAN, other people can easily reuse it. Of course, when you write an application module
The rules must be followed .)
To this end, pear came into being, and has been distributed along with the PHP core since 4.04.
What benefits does pear bring to me? & Nbsp;
1. As mentioned above, pear manages the pear application code library according to a certain classification. Your pear code can be organized into the appropriate
Other people can easily retrieve and share your results.
2. Pear is not only a code repository, but also a standard. Using this standard to write your PHP code will increase
Enhance the readability and reusability of your program and reduce the chance of errors.
3. Pear builds a framework for you by providing two classes to implement functions such as destructor and error capture.
You can use these functions.
Pear encoding rules & nbsp;
Pear encoding rules include indentation rules, control structures, function calls, function definitions, annotations, including code, PHP markup, text
The annotation block, CVS tag, URL sample, and constant naming in the header are as follows. The following is a brief introduction:
Indent rule: & nbsp;
In pear, four spaces are required for code reduction, and tab is not used. If you use vim, put the following settings into your
~ /. Vimrc: & nbsp;
Set & nbsp; expandtab
Set & nbsp; shiftwidth = 4
Set & nbsp; tabstop = 4
& Nbsp;
If you use Emacs/xemacs, set indent-Tabs-mode & nbsp; to nil.
But you like to use (x) Emacs to edit PHP files as I do, and I strongly recommend that you install PHP-MODE so that when you write pear generation
Code, it will automatically adjust your contraction style, of course, PHP-MODE has many excellent features, you can from the resource Column
Download the latest PHP-mode in the table.
Control Structure: & nbsp;
The control structures mentioned here include: & nbsp; If & nbsp; For & nbsp; while & nbsp; Switch & nbsp. For control structures, in keywords (such as if & nbsp; For & nbsp ;..)
Leave a space box and then use the parentheses to avoid confusion with function calls.
Use curly braces {}, even if the syntax is optional. This prevents new code lines from being generated.
Logical doubts or errors. Here is an example: & nbsp;
If & nbsp; (condition 1) & nbsp; (condition 2) & nbsp; esleif & nbsp; (Condition 3) & nbsp; │ & nbsp; (Condition 4) & nbsp; else & nbsp;
& Nbsp;
Function call: & nbsp;
For function calling, there should be no space between the function name and the left parenthesis (& nbsp;). For function parameters, separate the comma and the next parameter.
The numbers must be separated by spaces. The last parameter and the right brace cannot contain spaces. Below is a standard function call
Use; & nbsp;
$ Result & nbsp ;=& nbsp; Foo ($ param1, & nbsp; $ param2, & nbsp; $ param3 );
Non-standard writing:
$ Result = Foo & nbsp; ($ param1, $ param2, $ param3 );
$ Result = Foo (& nbsp; $ param1, $ param2, & nbsp; $ param3 & nbsp ;);
& Nbsp;
In addition, if you want to assign values to the result returned by the function, there must be a space between the equal sign and the assigned variable.
In a series of related assignment statements, you can add appropriate spaces to align them, just like this: & nbsp;
$ Result1 & nbsp ;=& nbsp; $ Foo ($ param1, & nbsp; $ param2, & nbsp; $ param3 );
$ Var2 & nbsp; & nbsp ;=& nbsp; $ Foo ($ param3 );
$ Var3 & nbsp; & nbsp ;=& nbsp; $ Foo ($ param4, & nbsp; $ param5 );
& Nbsp;
Function Definition: & nbsp;
The function definition follows the "One & nbsp; true & nbsp; brace" Convention: & nbsp;
Function & nbsp; Connect (& $ DSN, & nbsp; $ persistent & nbsp ;=& nbsp; false)
& Nbsp; else & nbsp;
& Nbsp; If & nbsp ;(! $ Dsninfo & nbsp; │ & nbsp ;! $ Dsninfo ['phptype ']) & nbsp;
& Nbsp; Return & nbsp; true;
}
& Nbsp;
As shown above, optional parameters must be at the end of the parameter table and always return meaningful function values whenever possible.
Note: & nbsp;
Online documents of classes should be converted to phpdoc, just like javadoc. Phpdoc is also a pear application.
For more details, go to & nbsp; http://www.phpdoc.de/ . We recommend that you use
Comments of non-document nature are used to interpret your code. When you see a piece of code, you may want:
Describe it. So you 'd better make a simple comment on the code to prevent you from forgetting how it works. For
In the form of annotations, C's & nbsp;/* & nbsp; */and C ++'s // are both good. However, do not use Perl or shell's # annotation method.
Code included: & nbsp;
Whenever you need to include a class file unconditionally, you must use requre_once.
To include a class file, you must use include_once; To ensure that the file you want to include will only be contained once, and
These two statements share the same file list, so you don't have to worry about confusion between them. Once require_once & nbsp; contains
File, include_once will not repeatedly contain the same file, and vice versa.
PHP code Tag: & nbsp;
Use & lt ;? PHP & nbsp ;? & Gt; Define Your PHP code, instead of simply using & lt ;? & Nbsp ;? & Gt; To ensure pear compatibility
Is also conducive to cross-platform migration.
Love J2EE follow Java Michael Jackson video station JSON online tools
Http://biancheng.dnbcw.info/php/323741.html pageno: 15.