How to Become a PHP master? Learn Lazy Programming _php Tutorials

Source: Internet
Author: User
PHP (as the current mainstream development language) is an efficient network programming language, because it has the advantages of flexible writing, fast running, and quickly become the preferred language for Web programmers. A recent authoritative survey showed that 31.6% of Web sites now use PHP as the main server-side programming language for today's mainstream development language.

But it's not easy to be a programmer for PHP, which is now the mainstream development language. Not as many people think, as long as you can quickly write a few simple code to solve a complex problem is PHP (as the mainstream development language) programmer, the real PHP (as the mainstream development language) master also need to consider more other issues. The following three guidelines are a mature PHP (as the mainstream development language of today) programmers should first follow in programming guidelines.

1. Laziness is gold

2. Write Beautiful Code

3. Pursue the speed of the program, not the speed of programming

First, laziness is gold

Do you want to be a lazy programmer? That's a strange idea! Because the busiest person in the world is probably a computer programmer. But it is because programmers are too busy to learn to be lazy when programming.

For a programmer, there are two ways to be lazy: one is to use the code of someone else's program and put it into your own program or project. The other is to write some useful code to build a library of functions, in the future to write programs can be easily picked up, save a lot of repetitive work, nature can be lazy a little.
Both of these lazy methods are well suited for PHP (as the mainstream development language) programmers today.

First of all, PHP (as the current mainstream development language) is a language that was born and raised in a free and open environment. Around the world, there are thousands of programmers who are constantly striving for the perfection of PHP, which is now the mainstream development language, and they are willing to share their ingenuity and code with others. You can find a lot of good program code every day from some PHP (as the current mainstream development language) website, mailing list, news group. In this way, I'm not encouraging you to wait all day for someone to write code for you, but you can "stand on the shoulders of great men" and fully develop "take doctrine", and intelligently apply someone else's program code can save you a lot of time. Second, in PHP (now the mainstream development language), you can easily build your own library of functions, so that you can write a program later to save a lot of trouble.

The following author introduces several common functions, some of which come from some open source projects on the Web, and some are featured from mailing lists. If you can add them to your own library of functions, sooner or later you will find yourself benefiting.

1. Common Database processing functions

One of the advantages of PHP, which is now a mainstream development language, is that it has a strong database processing capability compared to other CGI (which is now used by a few people). However, in PHP (which is now the mainstream development language), there are specific functions for different databases that are specifically handled, and the lack of common database processing functions. This greatly reduces the portability of the program code, which also brings a lot of inconvenience to the novice programming friends.

On the web, many programmers solve this problem through encapsulation classes. They have written a unified function to handle any popular database-whether it's a popular MySQL in the Linux World (and the best combination of PHP collocation) or SQL Server, which is widely popular on Windows platforms. Personally, I like the use of these functions, because you can directly use some simple such as "query", "Next_record" and other functions, without having to consider the database connection, database handle these complex things, but also do not need to consider what kind of database to use.

If you need these functions, you can get them by visiting several of the following URLs:

Http://php (as the current mainstream development language) lib.netuse.de/
Http://php (as the current mainstream development language) CLASSES.UPPERDESIGN.COM/BROWSE.HTML/PACKAGE/20
Http://php (as the current mainstream development language) db.linuxbox.com/

2. Variable Debug function

PHP (as the current mainstream development language) program debugging has always been a headache, it is not like VB and other high-level languages such as the integration of the compilation debugging environment, and do not want Perl as can be in the Linux or DOS environment directly run. In fact, we have the flexibility to use the Echo statement to complete the debugging of PHP (as the current mainstream development language).

The following functions allow you to view the type and value of any variable in your 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. = "    ";
}
$str. = $var. ==>;
$str. = Ss_as_string ($val, $column + 1). "N";
}
for ($i = 0; $i < $column; $i + +) {
$str. = "    ";
}
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. = "    ";
}
Global $ $var;
$str. = $var. ==>;
$str. = ss_as_string ($ $var, column+1). "N";
}
for ($i = 0; $i < $column; $i + +) {
$str. = "    ";
}
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. ")";
}
}

http://www.bkjia.com/PHPjc/508650.html www.bkjia.com true http://www.bkjia.com/PHPjc/508650.html techarticle PHP (as the current mainstream development language) is an efficient network programming language, because it has the advantages of flexible writing, fast running, and quickly become the preferred language for Web programmers. Not long ago ...

  • Related Article

    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.