October 14th, 2009

Minuses of use API of functions

* Not so evidently as system of patterns

* All the same, updating design needs some knowledge PHP

System of patterns

The second way used for division PHP and HTML of a code – use of patterns. In this case, some elements of design are replaced user tegami, and the program scans a file for their presence and replaces with their necessary information.

* Not so evidently as system of patterns

* All the same, updating design needs some knowledge PHP

System of patterns

The second way used for division PHP and HTML of a code – use of patterns. In this case, some elements of design are replaced user tegami, and the program scans a file for their presence and replaces with their necessary information.

Example of use of patterns:

<html>

<head>

<title> %% PAGE_TITLE %% </title>

</head>

<body %% BODY_PROPERTIES %%>

<h1> %% PAGE_TITLE %% </h1>

<table border = “0″ cellpadding = “0″ cellspacing = “0″>

<tr>

<td width = ” 25 % “> %% PAGE_LINKS %% </td>

<td> %% PAGE_CONTENT %% </td>

</tr>

</table>

</body>

</html>

Then we write the program which is looking through a code of a pattern and at a conclusion replacing tags of a kind %%: %% the necessary information.

The note: for his{its} use in system of patterns – FastTemplate, it{him} it is possible to download a quite good class with http://www.thewebmasters.net/.

Pluss of use of patterns:

* Extremely simply and clearly

* Change of patterns does not need knowledge PHP

Minuses of use of patterns:

* Slower way – in fact it is necessary to scan all pattern and only then to deduce{remove} the data

* It is more complex{difficult} to introduce in practice

15. Use of out-of-date syntax and functions

Some programmers again and again use old libraries and old operating time. For example, the code written still{even} under PHP 2, till now is used with PHP4 though already since version PHP3 the standard functions realizing same have been added.

Use of out-of-date functions and syntax can lower speed of performance of a code and, besides, make his{its} not readable. Other programmers can be unfamiliar with old functions. But nevertheless, if you have met a site of an old code, it is not necessary to copy it{him} in view of new rules of language. Simply it is not necessary to use it{him} at a spelling of new programs.

Example of use of old language designs:

<? php

// Old style

while (1):

print “5″;

if ($idx ++ == 5):

break;

endif;

endwhile;

// It is better to write so

// (however, the code can be optimized)

while (1)

{

print “5″;

if ($idx ++ == 5) {

break;

}

}

?>

Why it is necessary to follow new standards? The reasons the following:

* Use of old designs is not so distributed and, thus, newbies in PHP will be in confusion, having seen two different variants of syntax.

* Old syntax differs from syntax of other programming languages, and, hence, at transition from other language on PHP to the programmer it will be more complex{difficult} to understand and get used.

* But the most important – in one of new versions, probably, support of old syntax will be excluded, thus it will force you to copy a code anew. Anyway, brackets will always stay a part of language PHP.

Similar sites of a code can be met in many programs. You, as a rule, should be guided by the rules resulted in the documentation on PHP, the part updated – in her is reflected by the greater development of language. Periodically look through the documentation, in fact language develops, new functions are added. Thus, you never should write the user functions which are carrying out the same job, as standard.

The resume

In this clause{article} we have considered the first 7 of 21 most general{common} mistakes PHP of the programmer. As a rule, they do not break serviceability of programs, but, nevertheless, they should be avoided:

* Unreasonable application of function printf (): She{It} should be used only for a conclusion of the formatted data.

* Wrong application of semantics of language: Many programmers have no enough time to understand all subtleties of language, that subsequently is expressed in an erroneous code.

* Poorly kommentirovannyj a code: Always write comments! Before each function specify, that the given function, and what arguments she does{makes} demands. Also make comments on complex{difficult} sites of a code and brought changes.

* Too many time variables: Time variables are good for using for prevention of a repeated call of functions or sequences of functions.

* We invent a bicycle – it is copied standard function: First have a look in a management{manual} on PHP – whether function which you are going to is described there to write for, apparently, expansion of a set of standard functions PHP.

* It is mixed PHP and HTML a code: Try to make a code as more as possible modular. Then you (and another too) can replace design of page without change of code PHP.

* Old language designs and out-of-date functions are used: that you can make, not always it is necessary to do{make}. Have a look in the documentation and the literature on PHP how to write correctly. Excellent{different} books – ” Development of webs – applications with use PHP (Web Application Development with PHP) and ” Professional programmer PHP (Professional PHP). (EHkh where them still{even} to find!;)) – a comment of the translator)

Comments are closed.

footer

Design & programming by: Web Development Company CONKURENT LLC 2003-2009.