Every user has his or her own specific reason for using PHP to implement a mission-critical
application, although one could argue that such motives tend to fall into four key categories:
practicality, power, possibility, and price.
Practicality
From the very start, the PHP language was created with practicality in mind. After all, Lerdorf’s
original intention was not to design an entirely new language, but to resolve a problem that
had no readily available solution. Furthermore, much of PHP’s early evolution was not the
result of the explicit intention to improve the language itself, but rather to increase its utility to
the user. The result is a minimalist language, both in terms of what is required of the user and
in terms of the language’s syntactical requirements. For starters, a useful PHP script can consist of
as little as one line; unlike C, there is no need for the mandatory inclusion of libraries. For example,
the following represents a complete PHP script, the purpose of which is to output the current
date, in this case one formatted like September 23, 2005:
Another example of the language’s penchant for compactness is its ability to nest functions.
For example, you can effect numerous changes to a value on the same line by stacking functions
in a particular order, in the following case producing a pseudorandom string of five alphanumeric
characters, a3jh8 for instance:
$randomString = substr(md5(microtime()), 0, 5);
PHP is a loosely typed language, meaning there is no need to explicitly create, typecast, or
destroy a variable, although you are not prevented from doing so. PHP handles such matters
internally, creating variables on the fly as they are called in a script, and employing a best-guess
formula for automatically typecasting variables. For instance, PHP considers the following set
of statements to be perfectly valid:
$number = "5"; # $number is a string
$sum = 15 + $number; # Add an integer and string to produce integer
$sum = "twenty"; # Overwrite $sum with a string.
?>
PHP will also automatically destroy variables and return resources to the system when the
script completes. In these and in many other respects, by attempting to handle many of the
administrative aspects of programming internally, PHP allows the developer to concentrate
almost exclusively on the final goal, namely a working application.
0 komentar:
Posting Komentar