Learning PHP 5 201
Learning PHP 5 | |
author | David Sklar |
pages | 432 |
publisher | O'Reilly |
rating | 9 |
reviewer | John Suda |
ISBN | 0596005601 |
summary | An accessible introduction to the popular web scripting language PHP |
This book is not particularly useful for those experienced already with PHP, nor for those wanting to upgrade their knowledge of PHP from versions 4 and earlier to the newest version. It's also probably not particularly useful for those power programmers who need and want a deep and comprehensive coverage of the topic. But it is a very well-written and designed introduction to PHP 5 for beginning programmers or those experienced PERL, ASP, or Cold Fusion programmers who want to learn a different language. There are many illustrations and code samples sprinkled throughout the book. Sklar, however, skims over some topics, concentrating instead on practical examples.
The publisher is O'Reilly Media, Inc. which seems to have an editor's policy of covering complex computer-related topics in a comprehensive manner by publishing a range of volumes covering different aspects of a topic or from different angles or for different audiences. O'Reilly also publishes volumes on moving to PHP 5 (Upgrading to PHP 5), detailed and technical PHP (Programming PHP), and a collection of solutions to common PHP programming problems (The PHP Cookbook).
Sklar is an experienced consultant in computer software development and technical training. He is the author of Essential PHP Tools and coauthor of the aforementioned The PHP Cookbook. He takes a deliberate and comprehensive approach to explaining PHP 5, not in great depth, but with the intent of providing enough information, concepts, detail, and scope to create a pleasant and useful read of a technical subject. The basic promise of PHP is in the relatively easy creation of more dynamic and interesting web sites which would include, for example, product catalogs, blogs, photo galleries, event calendars, forms, and more.
There are 13 chapters and 3 appendices. The early chapters provide an orientation to PHP, including its place in contemporary web development, its basic rules, and its syntax. They explain the basic background of PHP and how it interacts with the browser and web server. Later chapters introduce primary concepts like loops, arrays, and functions. The idea here is to facilitate learning the fundamentals of the grammar and vocabulary. Chapters 2 through 12 have short exercises at the end of each to allow the reader to practice writing PHP code and to test learning. (The answers are contained in Appendix C.) Experienced programmers and geeks may recoil at the inclusion of these exercises, but they are useful for beginners.
Chapter 6 provides a practical exercise - how to make and use a web form. The author shows how to access form variables, how to validate user-inputted data for security and efficiency reasons, and how to process forms using functions. Chapter 7 shows how PHP interacts with database programs, like SQL and Oracle, but focuses primarily on MySQL, and demonstrates how to organize data, connect to a server-based database, create tables, and enter and retrieve data.
The rest of the middle chapters cover the use and implementation of cookies and sessions, handling dates and time, and working with files. The practical exercise using dates and times is creating and displaying a monthly calendar. The final chapters provide brief but practical coverage of XML, debugging, and in Chapter 13, other PHP aspects. PHP is amazingly useful, flexible, and practical. One can deal with graphics, PDF documents, and other media like Flash and Shockwave. It also has mailing and file uploading functions, encryption capabilities, and (for more experienced coders) the ability to run shell commands. The upgraded PHP 5 has new capabilities, which now include object-oriented programming.
Appendix A covers installing and configuring PHP for Windows, Mac OS X, and Linux; Appendix B is a short primer on regular expressions and how to use them with PHP.
I found the book to be the most accessible introduction to PHP I have read. It provides the basic fundamentals, engages the reader in practical examples, reinforces learning with exercises, and provides an overall perspective on the scope of PHP programming.
You can purchase Learning PHP 5 from bn.com. (Code examples used in the book can be downloaded at the O'Reilly site for the book, linked above.) Slashdot welcomes readers' book reviews -- to see your own review here, read the book review guidelines, then visit the submission page.
Two free books on PHP (Score:5, Informative)
A Programmer's Introduction to PHP 4.0 [apress.com] from Apress
Practical PHP Programming [hudzilla.org] online book
Re:Two free books on PHP (Score:1, Redundant)
I have a bit of a bone to pick. (Score:5, Interesting)
You say that PHP's "OOP model" "sucks". First off, the term "OOP model" is frankly idiotic. OOP isn't enough of a coherent programming paradigm to be considered a single "model" or "base". Further, only PHP 4 has inferior OOP features. Why? Simply because they weren't in demand. Most people don't need OOP. It's overengineering overkill for the vast majority of applications.
It's also been alleged that PHP is somehow slower than Perl or Python for Web. However, Perl and Python all have to be compiled before execution, much the same as PHP. It's well known that PHP compilers and cachers already exist, so there's no reason why running the smallest PHP script shouldn't take any more than perhaps a 1/400 of a second. That's a pretty reasonable time, no?
PHP is maturing. Its version number is the same as Perl; it's more popular than Perl; it's almost as mature as Perl. It has more users than Perl, more bug fixes being put out, and its few idiosyncrasies are very well known. Frankly, there's fewer traps for a beginning PHP user than a beginning Perl user.
Re:I have a bit of a bone to pick. (Score:1)
Re:I have a bit of a bone to pick. (Score:1, Insightful)
Re:I have a bit of a bone to pick. (Score:3, Informative)
And for those zealots who bitch about the fact that everything's a function, dive into Pear...
The only thing that'll keep php5 from getting into the mainstream is the fact that it doesn't offer too much more other than a much better implementation of OOP, and default installs don't have the mysql package by default - they only have imysql
Re:I have a bit of a bone to pick. (Score:2)
Problem is that mysql-stable doesn't work with the imysql package... mysql-stable is still mysql 4.1 last time I checked. In a production environment you need a stable database (granted going to PHP5 is a bit of premature ejaculation IMO).
Re:I have a bit of a bone to pick. (Score:5, Insightful)
Honestly, PHP is MUCH better than perl if you want to write web applications. I still use perl for anything that I need to run from the command line, but for web stuff, it's PHP all the way.
Now, PHP does have some pretty significant flaws, and perl does a lot of stuff far better than PHP, but PHP is so far superior at doing web-related things that it's silly to write web applications with perl instead of PHP, unless there is some functionality that app depends on that PHP just can't do at all.
By the way, saying you refuse to even look at another language because the language you use is so damn cool makes you a zealot, whether you want to admit it or not. Any good programmer should be willing to investigate and learn new languages. Nearly every language has its niche where it is better than any other language at doing whatever it does. With PHP, that niche is web applications.
Re:I have a bit of a bone to pick. (Score:1)
Re:I have a bit of a bone to pick. (Score:2)
What does it do differently? (Score:5, Interesting)
Re:What does it do differently? (Score:5, Insightful)
Re:What does it do differently? (Score:2)
ASP.NET and PHP5 explained (Score:5, Informative)
PHP5 has more features than PHP4 but is aggressively backwards compatible, thus, with a few exceptions it's as crufty as ever.
I would pick OpenACS [openacs.org] over ASP.NET but I would pick ASP.NET over PHP5 or most J2EE stacks.
Re:ASP.NET and PHP5 explained (Score:2)
Re:ASP.NET and PHP5 explained (Score:2)
At work we've moved many complex database driven/CMS sites written in PHP4 to PHP5 with no modifications at all.
Re:ASP.NET and PHP5 explained (Score:2)
You can see Backward Incompatible Changes [php.net] and new keywords [php.net] for the things that may cause problems for you.
The biggest issues I can forsee is if you currently use some of the new keywords in
Re:ASP.NET and PHP5 explained (Score:1)
Anyways, the biggest redesign with PHP5 is its Object-Oriented Model. It now reflects to what a true OO model should be such as Private and Protected Members, Final, Private, Protected and Static Methods, class abstraction, Interfaces and a standardized constructor and destructor syntax.
The backwards compatibility comes from everything else with PHP. Pretty much all the functions remain intake
Re:What does it do differently? (Score:3, Insightful)
To be honest, if you've never used ASP.net, then it is difficult to explain the differences. But for the web, nothing else comes close.
Re:What does it do differently? (Score:2)
Re:What does it do differently? (Score:1)
PHP5 will not write Javascript for you. If you want the client to "work with data without page reloads", you've got to get your hands dirty. Not that I mind doing that. Generating Javascript via PHP can be fun!
Re:What does it do differently? (Score:3, Informative)
The original ASP wasn't a language, it was a framework too. You could write ASP pages in vbscript, jscript or even perl.
Re:What does it do differently? (Score:1)
This implys that ASP did not have OOP features. In fact, J(ava)Script has a powerful 'prototype'-based OO system. Even VBScript has basic OO -- about the same as normal VB.
(It's funny how ASP got such a bad rap from PHPers, but PHP is just now getting many of the features that ASP had years before it went obsolete.)
Re:What does it do differently? (Score:2)
Re:What does it do differently? (Score:1)
See Zend PHP 5 press release [zend.com]
this is what's new in PHP 5...
Summary:
Zend Engine II has Object-Oriented development features for component-based enterprise applications
Extended XML support
Support for web services
Enhanced Database support
Re:What does it do differently? (Score:5, Insightful)
PHP5 competes with ASP.NET (and Java) up to a certain point. This is a question of best tool for the job. PHP5 is great for developing interactive websites, CMS/forums/blogs, and other lightweight web applications as suitable for an inexpensive hosted environment. However, PHP5 is still way behind today's Java and
So it comes down to this: if your application is simple enough, by all means use PHP5. It is a great tool for limited-scope jobs (analogous to VisualBasic for the web perhaps) and its performance and scalability is excellent given its limited-by-design architecture. Simplicity on the low end is PHP's strength.. it doesn't try to do too much for those who don't need it to! On the other hand, if your application is more complex (most business apps, anything accounting / finance related, mission critical databases, etc.) use a modern, lightweight, framework-driven Java approach like Spring + Hibernate. PHP is no longer the "simplest thing that could work" when the application domain has moved beyond what it naturally does well. You can force the use of just about any language for any given task but that doesn't mean it makes sense to. (and spare me the silly politics..)
Choice is good. What does disturb me is how many open source programmers today think that PHP, Perl, and Python are the answer to everything web-related. They're not. I could name a few dozen projects currently using those language that would be far better off using Java instead. Incidentally, Python is the closest to competing directly with Java's domain, but needs a few more years for its tools to mature.
http://www.extremeprogramming.org/rules/simple.
http://www.springframework.org
Re:What does it do differently? (Score:3, Insightful)
There is a very subtle line in the sand where PHP becomes 'underkill' and you need to consider moving to a more rounded technology like J2EE or (*spit*)
There are far too many people using J2EE and
Also, the other way ar
Re:What does it do differently? (Score:2)
The problem is that no current web frameworks get i
Re:What does it do differently? (Score:2)
It depends on what your needs are. Some complexity simply cannot be avoided given today's technology. Also, keep in mind that VB/Delphi would also represent "too much coding" if it were not for their RAD GUIs that do a lot of work for you and hide much of the "glue" that holds everything together. On the Java side, you have tools like Eclipse that perform similar functionality, albeit with a bit more develo
Re:What does it do differently? (Score:1)
PHP vs Zope, Pearl vs Python (Score:5, Interesting)
Slightly later I did a web project where some interaction was necessary. Instead of my old cgi-scripts or DHTML, I started it in PHP and Zope, as a newbie in both. While recognizing that Zope seems very clean I was totally unable to wrap my head around its basic concepts ('TAL' anyone ?). In one afternoon I had PHP installed and a 140 pages of PHP converted from HTML, up and running. Going from HTML to basic PHP takes about 5 minutes.
So, while I regret to say that, some languages look cool but others just do the job. PHP is certainly one of the latter.
In fairness to the python community (Score:4, Interesting)
WebWare and Quixote are probably the biggest; another called SnakeSkin was just announced as having reached 1.0 today.
Back in my day... (Score:5, Insightful)
And we liked it that way!
Re:Back in my day... (Score:1)
Re:Back in my day... (Score:2)
We would figure out what to do by tracing through the assembly code on paper!
You youngins have it good these days.
Re:Back in my day... (Score:1)
Re:Back in my day... (Score:1)
Re:Back in my day... (Score:2)
Re:PHP "documentation" is CRAP! (Score:1)
I'm sorry, but that's like a troll at it's finest. Granted, SOME pages have issues, but I have yet to find a PHP doc page where if the actal 'documenation' was insufficient, the users didn't comment/correct/fix.
Re:PHP "documentation" is CRAP! (Score:1)
This isn't what I would call a nicely collated and well written reference fit for anybody but the most hard-core, open-source-brainwashed, developer to put up with. There is some open source documentation which is actually good, say, Perl, but PHP isn't very coherent!
open-source vs. suitability to task (Score:2, Insightful)
So, being open-source is more important than suitability to task?
Re:open-source vs. suitability to task (Score:2, Insightful)
If it's open source and clumsy, it will can always evolve into something better. If it isn't, well, they got your money once, and you better be happy.
Re:open-source vs. suitability to task (Score:2)
So you would be happy if your bank lost money from your account due to clumsy free software, just so they could use free software out of principle?
Right tool for the right job. In some circumstances the development team dont have time to wait for the software to mature, nor do they have the resources to help develop said software. They have to work with something that is mature and stable NOW. If that happens to be commerc
Re:open-source vs. suitability to task (Score:4, Interesting)
For many of us, being Free Software is "suitability to task". That is, non-Free software is an automatic disqualification from the running.
I've built my company's web apps on Zope, Python, PostgreSQL, and FreeBSD. None of those "vendors" will go out of business next year (but if they did, who cares?). There will be no forced upgrade to a more expensive version that we don't need. We can get timely (and free) security updates and feature upgrades. We have an infinite-user license.
How on Earth could a closed vendor compete with that? The answer: they can't. There are far too many Free options for developing network applications to even glance at the proprietary stuff.
Oh, and my boss likes our system so much that he just gave me permission to release all of the non-business-logic software I've written over the last year under an open source license. The only remaining step is to pick the license that we'll use to share our work with the community that made it all possible. Have I mentioned today that I dig my job?
Re:open-source vs. suitability to task (Score:2)
How on Earth could a closed vendor compete with that? The answer: they can't.
oh, I don't know, possibly by providing a product that actually works, and increases productivity, versus an inferior copy-of-features, slightly usable program.
That is not to say OpenS software is inferior (plenty are amazing--linux,mozilla,openoffice,etc..), just commenting on your seeming blind adoption of it just because it's OpenS.
For those who like this book (Score:1)
honest question here... (Score:4, Insightful)
Just curious.
Re:honest question here... (Score:3, Insightful)
Re:honest question here... (Score:2)
We all have different methods or modalities for processing information -- some people get the most from listening to lectures, others from reading, others from doing hands-on, others from dissecting/disassembling things.
Recently someone observed that I do a lot of handwritten notetaking, highlighting, 'circles 'n arrows.' It made me realize that, for example, I understand code so much better if I print it out, write notes, draw boxes, etc. When I do pseudocode, the ideas flow better if I write by hand, do
The fast way to learn PHP.... (Score:5, Funny)
No! (Score:2)
Kuru [wikipedia.org] is bad.
Shake a joystick... (Score:1, Funny)
Sure you can. I did it just last week. If you want proof, just look at the police report.
I read it (Score:5, Informative)
The bit on XML was interesting as I've never needed to use XML and now have a single practical example to point at.
The book is not a 9...more like a 6. It's a professional paperback monolith and it doesnt spread disinformation. I don't know what's wrong with the reviewer *shrug* but this isn't a book I'd recommend.
Re:I read it (Score:2)
So tell us... (Score:2)
Re:So tell us... (Score:2)
If someone where to ask me about learning PHP, I'd tell them to scratch an itch, using php.net, then buy The PHP Anthology [sitepoint.com] from sitepoint. Great stuff. I think it has been reviewed here before but I'm too lazy to look. Anyway, you can download a couple of sample chapters to see if you're interested.
Re:I read it (Score:2)
php rocks (Score:1)
Lots of PHP Book Reviews (Score:2)
They must be publishing these things like mad.
Coming from a background in Bash (Score:2)
I don't understand why people are critical of this book. It is basic, yes, but it is targeted for beginners anyhow. Is it comprehensive? No, but then there are hardly any books that are on a given language.
Hell, even John Carmack bought the "Camel Book" when he needed to learn perl, and as he said, leigons of people would have laughed, or bee
I have the book! (Score:1)
Job Lobby (Score:2, Insightful)
Now if only I could find a job writing it!
It seems most of the jobs here are ASP related mostly because Microsoft actively sells their product, there is no one selling Free alternatives.
Re:Job Lobby (Score:2)
I got hired two weeks after I sent mine in, and I've loved my job ever since.
php5 Host ? (Score:1, Informative)
http://www.a2webhosting.com/ [a2webhosting.com]
Re: (Score:2)
Good book, better teacher (Score:1)
I just had a week of training with the author... (Score:2, Interesting)
... At Big Nerd Ranch [bignerdranch.com], and it was awesome. If you like the book and you want more personal training, they're talking about doing this PHP5 bootcamp again in about 5 months. It's held at a fantastic retreat setting in georgia, so it's fairly free from distraction. If you've tried to find PHP training, you know this is an unserviced market largely, so if/when they offer this class again, jump on it fast.
I've been about 3 years into self-taught programming with books, open source examples, and trial and l
Learn PHP without a book (Score:1, Redundant)
More PHP suppliments (Score:3, Informative)
Yes, yes, it's a shameless plug, but I had a lot of fun putting it together
Any good IDEs? (Score:2)
Re:Any good IDEs? (Score:2)
Re:Any good IDEs? (Score:2, Informative)
Re:Any good IDEs? (Score:2)
Coming from a Perl background... (Score:2, Insightful)
Re:but (Score:1, Offtopic)
Re:but (Score:1, Offtopic)
Re:PHP or Perl? (Score:2, Interesting)
Re:PHP or Perl? (Score:2)
Re:PHP or Perl? (Score:1)
Re:PHP or Perl? (Score:3, Insightful)
After about 3 months of playing
Perl will serve you online and off (Score:1, Insightful)
Re:Perl will serve you online and off (Score:1)
Re:PHP or Perl? (Score:3, Interesting)
Some of the reasons I prefer PHP over perl is because it's a lot more similar to
Re:PHP or Perl? (Score:3, Informative)
Uh? >perl -MCPAN -e "install mymodule"
which will also track down dependencies and install those too.
Can it be any easier? Activestate has their own set of tools to do the same.
And you typically install or update modules because there is some spiffy module like Net::SFTP, Math::VectorReal or AI::N
Re:PHP or Perl? (Score:1)
Re:PHP or Perl? (Score:3, Informative)
use lib
or
push @INC, './my_module_dir';
and perl will look in your private locations for required add-on modules.
This model of installing modules as needed for a parser is unlike most other languages, and is something most people haven't taken too
Actually it is similar for every other language including compiled C when
Re:PHP or Perl? (Score:1)
Yes, but it's rare to use these modules in PHP, where as it's really common to need a Perl module from CPAN that you don't already have or have too old of a version.
Incidentally, CPAN borrowed its name from CTAN, the Comprehensive TeX Archive Network. Java has JNLP, etc.
That would explain why most people who like perl also seem to enjoy java and tex. It's really just a matter of preference whether you like these things, and from what I've seen a lot
Re:PHP or Perl? (Score:2, Insightful)
Re:PHP or Perl? (Score:2)
Reason being is the rendering engine is run in the webserver itself. Not interpretted through a cgi interface.
My information might be obsolete since I left the IT world in discuss in 2001 so feel free to correct me.
Re:PHP or Perl? (Score:2, Insightful)
Not saying that C isn't a great language for some things, but it is not a great lang
Re:Word Basher! (Score:1)
Re:PHP or Perl? (Score:3, Insightful)
If, on the other hand, you are not a masochist, you want to write something quickly and easily, something relatively easy to debug, something that isn't going to get multiple hits per second - use PHP. That's what it's there for.
Re:Help is on the way... (Score:3, Informative)
Re:PHP - poor design (Score:2, Funny)
Hmmm... I code J2EE (WebSphere) and I must say PHP is much more graceful than Java. I can send an email in one line of PHP code, but with Java, if I'm not using J2EE, I have to make sure I have the JavaMail and JAF libraries manually installed and then regardless, write or download a wrapper class (with prolly 100+ lines of code) to do something that any language ought to be able to do with
Re:PHP - poor design (Score:3, Interesting)
The number of sorting routines isn't necessarily bad - they're all well documented, and all have differences. I don't think having multiple sort routines slows the language down at all, so I don't see the problem.
One might think that having all these different routines might make it easier t
Re:PHP - poor design (Score:3, Interesting)
That is almost certainly not what the OP meant. Staying language generic, suppose you have an array of two-element arrays:
[[1, 3], [2, 2], [3, 1]]
and you want to sort this array by the second element. In Perl, that's
Re:PHP - poor design (Score:3, Insightful)
Now the real question is how do I get /. to indent
my code properly?
Re:PHP - poor design (Score:2)
Re:PHP - poor design (Score:2)
So blah.
Re:PHP vs asp.net (Score:2)
If you have to run it on a non-windows platform, PHP is more suited than ASP - I think there's an ASP module for apache, but I don't think the ASP.NET module and mono are quite working well together.
Also, there's a heck of a lot of community-contributed code. Something like PEAR is a great resource for extra functionality in your PHP scripts. I also find that there's more free documentation, t