One of the more prominent features of PHP is its vast collection of built-in functions, even before
you start adding in optional extensions. This is arguably a failing because it makes the job of
deciding which function to use in a given situation that much more difficult. Many of the functions
are so similar in behavior that it’s sometimes hard to see why they exist as distinct functions.
split() or preg_split()? str_replace() or strtr()? ksort(), asort(), rsort(),
natsort(), usort() or uksort()? strftime() or date()? This book doesn’t go into the lack
of conventions regarding the naming of functions or the order of arguments, or the way in which
several functions are merely aliases of others.
One cause of PHP’s overlapping set of functions is its early existence as a mere wrapper over
Perl’s and later C’s own libraries. Users familiar with those languages’ function libraries would
find their PHP equivalents going by the same names with the same calling conventions, overlaid
with PHP’s memory management and type handling. Extensions exacerbated this—with different
DBMSs exposing different APIs, PHP introduced different sets of functions for each DBMS it supported.
When two extensions boasted functions for two similar things, PHP provided both.
As PHP became implemented more expansively on a wider variety of platforms and built into a
wider variety of environments, platform-independent implementations of functions began to be
introduced. Hence the existence of both rand() (which uses whatever pseudorandom number
generator was supplied by the C compiler PHP was built on) and mt_rand() (which has identical
behavior across all platforms). At the same time, PHP developers have been committed to backward-
compatibility; even as new mechanisms are introduced, they do their best to retain the old
ones in case there are people relying on them.
So PHP’s function list burgeoned, bulging out like a loaf of bread rising in a tin that’s too small for
it. At last count, the PHP manual had 3,630 function entries, distributed among 129 chapters, of
which 855 are listed in the 30 chapters that the manual describes as “core” or are bundled and
require an explicit configuration switch to disable. Those figures are already out of date.
The practical upshot of this is that many PHP programmers are like English speakers—they use
only a small subset of the language. There are parts of the language they may just not have any use for. But hidden among PHP’s esoterica are some functions that don’t get the attention they deserve. These
are functions that have been present in PHP since version 4.3.2 at the latest—many have been around
since the early days of PHP 4. Despite this, they are often overlooked, even when they are ideal for the
task at hand. Some of them seem to be used only in tutorials about them. They are by no means the only
obscure features of the language. Rather, they represent some of the more powerful core functionality of
the PHP environment and are areas which are the site of active development in recent versions.
This chapter seeks to redress some of this injustice.
From: Profressional LAMP
ไม่มีความคิดเห็น:
แสดงความคิดเห็น
If you want an answer, you have to ask....