General Language Features
General Language Features
Every user has specific reasons 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
language that allows the user to build powerful applications even with a minimum of knowledge. For
instance, 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
Don’t worry if this looks foreign to you. In later chapters, the PHP syntax will be explained in great
detail. For the moment, just try to get the gist of what’s going on.
Another example of the language’s penchant for compactness is its ability to nest functions. For
instance, you can effect numerous changes to a value on the same line by stacking functions in a
particular order. The following example produces a string of five alphanumeric characters such
as a3jh8:
$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:
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.
Yorumlar
Yorum Gönder