Docstoc

Introduction PHP

Document Sample
Introduction PHP Powered By Docstoc
					What Does PHP Do?
PHP does anything you want, except sit on its head and spin. Actually, with a little
on-the-fly image manipulation and Dynamic HTML, it could probably do that, too.

According to the PHP manual, "The goal of the language is to allow web developers
to write dynamically generated pages quickly."

Here are some common uses of PHP, all of which are part of what you'll learn in this
book:

      Perform system functions: create, open, read from, write to, and close files
       on your system; execute system commands; create directories; and modify
       permissions.
      Gather data from forms: save the data to a file, send data via e-mail, and
       return manipulated data to the user.
      Access databases and generate content on-the-fly, or create a web interface
       for adding, deleting, and modifying elements within your database.
      Set cookies and access cookie variables.
      Start sessions and use session variables and objects.
      Restrict access to sections of your website.
      Create images on-the-fly.
      Encrypt data.

These are just basic, everyday uses. PHP also includes support for integrating with
Java servlets, XML, and a myriad of other higher-level functions. The possibilities
literally are endless.




Why PHP 5?
It's natural that languages continue to develop, and PHP 5 has done just that—its
changes represent the next step in the growth and development of the language.
There was nothing fundamentally wrong with PHP 4, and in fact the vast majority of
this book can be used on servers running PHP 4 and not PHP 5. The changes in PHP
5 revolve around high-level aspects of the language, namely the object model.

If you are coming to PHP from another programming languages, especially a highly
structured, specifically object-oriented language, the crossover to a flexible,
procedural language that just happens to handle object-oriented programming can
be frustrating. But, the ease of use and robustness is one of the reasons new
programmers are drawn to PHP in the first place—the learning curve isn't steep, and
it gets the job done.
However, this also presents a marketing problem for PHP users working in an
enterprise setting. Some Powers That Be might not think PHP is suitable for
enterprise-level application development, because it is not a time-tested, structured,
object-oriented programming language such as C or even Java. There might not be
the time or opportunity for a developer to convince her managers otherwise by
showing examples of PHP and C or Java performing the same tasks—if you even
can, with the same level of structure, security, reusability, and exception-handling.

From these and other problems came the development path for PHP 5, the main
purposes of which were to improve the object model, instill a sense of programming
discipline, and specifically design a version of PHP that meets the needs of object-
oriented developers and allows them to interface with Java, .NET, and other
enterprise-level application frameworks.

But beginning users—likely the primary audience of this book—will not face objects,
classes, .NET, or XML-integration their first day on the job. These users simply want
a fast, flexible language they can use to create basic, dynamic websites, and PHP 5
still meets that need. Although PHP 5 contains an enhanced internal scripting engine
and a vastly improved object-oriented framework, the PHP Group and Zend
Technologies recognize and appreciate the roots of PHP and the core group of users
who have made it so pervasive. As with PHP 4, PHP 5 does not force you to use the
elements of the language you don't need.

Overview of Changes in PHP 5

Because this book does not provide lessons in programming PHP from an object-
oriented point of view, this section will not go into detail and show examples of the
object model changes in PHP 5. For that, I highly recommend Harry Fuecks' article
"PHP5: Coming Soon to a Webserver Near You," at
http://www.sitepoint.com/article/1192/. This article contains an outstanding
dissection of the object-related changes in PHP 5, and how to implement them.

A few other major features are part of PHP 5, including the appearance of SQLite, an
embedded database engine. This is not at all meant to replace a robust database
like MySQL, PostgreSQL, or Oracle. Instead, this simple, speedy little database can
store database files in both files and memory and thus would be good for something
like storing session data and application configuration information—simple INSERTs
and SELECTs. Although this book uses MySQL as its database of choice, you can
learn more about SQLite .

Another change is in the XML arena. PHP 4 used several third-party libraries to
control XML parsing and rendering, thus there was no single stable and reliable XML
rendering and parsing mechanism. PHP 5 provides one XML library, Gnome's libxml,
as the foundation for the DOM extension. This library is very fast and full-featured,
and thus a solid foundation on which to rebuild the XML functionality in PHP. You will
learn more about working with XML in PHP 5.
Backwards Compatibility with PHP 4

The changelog and PHP manual always indicate when a new implementation will
cause problems in previous versions, so at least read the changelog thoroughly if not
the manual entries for your favorite functions. However, the vast majority of PHP 5
focuses on additional functionality rather than completely replacing existing
elements. If you have learned PHP using PHP 4, you might find that none of your
scripts require a rewrite.

Requiring a rewrite and rewriting scripts for the sake of utilizing new functionality
are completely different—you might want to rewrite to take advantage of new
object-oriented functionality, but you might not have to. If your code is primarily
procedural (as with the scripts in this book), there's a better than 95% chance that
no rewrites will be necessary.

Similarly, if you cannot install PHP on your own machine for development or product
purposes "Installing PHP," and must use PHP 4, do not fret. Anything taught in this
book that doesn't work in PHP 4 is indicated as such.

Is PHP Right for You?
Only you can decide if PHP should be your language of choice, whether you're
developing sites for personal or commercial use on a small or large scale. I can only
tell you that in the commercial realm, I've worked with all the popular server-side
scripting languages—Active Server Pages (ASP), ColdFusion, JavaServer Pages (JSP),
Perl, and PHP—on numerous platforms and various web servers, with varying
degrees of success. PHP is the right choice for me: it's flexible, fast, and simple in its
requirements, yet powerful in its output.

Before deciding whether to use PHP in a large-scale or commercial environment,
consider your answers to these questions:

      Can you say with absolute certainty that you will always use the same web
       server hardware and software? If not, look for something cross-platform that
       is available for all types of web servers: PHP.
      Will you always have the exact same development team comprised entirely of
       ASP (or Java Server Pages or ColdFusion) developers? Or will you use
       whoever is available, thus necessitating a language that is easy to learn and
       syntactically similar to C and Perl? If you have reason to believe that your ASP
       or JSP or ColdFusion developers might drop off the face of the earth, don't
       use those tools—use PHP.
      Are memory and server load an issue? If so, don't use bloated third-party
       software that leaks precious memory—use PHP.

Here's the bottom line: PHP is simple, so just try it! If you like it, continue using it.
It's Open Source, so help improve it. Join a mailing list and help others. If you don't
like it, you're only out the money for this book, and the software can be uninstalled
without rendering your machine completely inoperable.

				
DOCUMENT INFO
Shared By:
Categories:
Tags: computer
Stats:
views:9
posted:2/10/2011
language:English
pages:4
Description: Introduction PHP