How can we become a PHP master? Learn lazy Programming

Source: Internet
Author: User

Php (as the mainstream development language) is an efficient network programming language. It has the advantages of flexible writing and fast running, and quickly becomes the preferred language for Web programmers. A recent authoritative survey showed that 31.6% of websites now use php (as the mainstream development language) as the main server programming language.

However, it is not easy to become a php (as the mainstream development language) programming expert. Not as many people think, as long as they can quickly write a few simple code to solve a complicated problem, php (as the mainstream development language) programming experts, the real php (as the mainstream development language) experts also need to consider more other issues. The following three principles should be followed by a mature php (as the mainstream development language) programmer in programming.

1. Laziness is gold

2. write beautiful code

3. The pursuit of program speed rather than programming speed

1. Laziness is gold

Be a lazy programmer? This is a strange idea! This is because the busiest person in the world may be a computer programmer. But it is because programmers are too busy that they should learn to be lazy during programming.

For a programmer, there are two lazy Methods: First, boldly use the code of someone else's program to integrate the code into your own program or project. The second is to write some useful code to create a function library, which can be easily written in the future, saving a lot of repetitive work, so you can naturally be a little lazy.
These two lazy methods are very suitable for php programmers (as the mainstream development language.

First, php (as the mainstream development language) is a language that was born and developed in a free and open environment. There are thousands of programmers around the world who are constantly striving for the perfection of php (as the mainstream development language, they are willing to share their talents and code with others. Every day, you can find a lot of excellent program code from some php websites, email lists, and newsgroups. In this way, I do not encourage you to wait all day for others to write code for you, but you can "stand on the shoulders of great people" and fully carry forward "ism ", smart Application of others' program code can save you a lot of time. Second, in php (as the mainstream development language), you can easily create your own function library, which saves you a lot of trouble in programming later.

Below I will introduce several common functions, some of which come from some open source projects on the Internet and some of which are selected from the mail list. If you can add them to your own function library, sooner or later you will find yourself benefiting.

1. Common Database processing functions

Compared with other cgi (not many people are using it now) functions, php (as a mainstream development language) has powerful database processing capabilities. However, in php (as the mainstream development language), some specific functions are used for different databases for special processing, and common database processing functions are missing. This greatly reduces the portability of program code, which also brings a lot of inconvenience to beginners.

On the Internet, many programmers solve this problem through encapsulation. They have compiled unified functions to deal with any popular database, whether it's MySQL, the best combination of PHP and SQL Server, which is popular on the Linux World. I personally like to use these functions, because some simple functions such as "query" and "next_record" can be used directly, you do not need to consider the complex things such as database connection and database handle, and do not need to consider what type of database is used.

If you need these functions, you can access the following urls:

Http: // php (as the mainstream development language) lib.netuse.de/
Http: // php (as the mainstream development language) classes.UpperDesign.com/browse.html/package/20
Http: // php (as the mainstream development language) db.linuxbox.com/

2. Variable debugging Functions

Debugging of php (as the mainstream development language) Programs has always been a headache. It does not have an integrated compilation and debugging environment like other advanced languages such as VB, and do not want Perl to run in a Linux or DOS environment. In fact, we can use echo statements flexibly to debug php (as the mainstream development language.

The following functions allow you to view the types and values of any variables in the program at any time.

Function ss_array_as_string (& $ array, $ column = 0 ){
$ Str = "Array (n ";
While (list ($ var, $ val) = each ($ array )){
For ($ I = 0; $ I <$ column + 1; $ I ++ ){
$ Str. = "& nbsp ;";
}
$ Str. = $ var. =>;
$ Str. = ss_as_string ($ val, $ column + 1). "n ";
}
For ($ I = 0; $ I <$ column; $ I ++ ){
$ Str. = "& nbsp ;";
}
Return $ str .);
}
Function ss_object_as_string (& $ object, $ column = 0 ){
If (empty ($ object-> classname )){
Return "$ object ";
}
Else {
$ Str = $ object-> classname. "(n ";
While (list (, $ var) = each ($ object-> persistent_slots )){
For ($ I = 0; $ I <$ column; $ I ++ ){
$ Str. = "& nbsp ;";
}
Global $ var;
$ Str. = $ var. =>;
$ Str. = ss_as_string ($ var, column + 1). "n ";
}
For ($ I = 0; $ I <$ column; $ I ++ ){
$ Str. = "& nbsp ;";
}
Return $ str .);
}
}
Function ss_as_string (& $ thing, $ column = 0 ){
If (is_object ($ thing )){
Return ss_object_as_string ($ thing, $ column );
}
Elseif (is_array ($ thing )){
Return ss_array_as_string ($ thing, $ column );
}
Elseif (is_double ($ thing )){
Return "Double (". $ thing .")";
}
Elseif (is_long ($ thing )){
Return "Long (". $ thing .")";
}
Elseif (is_string ($ thing )){
Return "String (". $ thing .")";
}
Else {
Return "Unknown (". $ thing .")";
}
}

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.