Beta
×

Welcome to the Slashdot Beta site -- learn more here. Use the link in the footer or click here to return to the Classic version of Slashdot.

Thank you!

Before you choose to head back to the Classic look of the site, we'd appreciate it if you share your thoughts on the Beta; your feedback is what drives our ongoing development.

Beta is different and we value you taking the time to try it out. Please take a look at the changes we've made in Beta and  learn more about it. Thanks for reading, and for making the site better!

Learning PHP 5

timothy posted more than 9 years ago | from the learn-to-pronounce-it-too dept.

Books 201

John Suda writes "There are more new books being published about PHP than you can shake a joystick at. PHP (along with program friends - MySQL and Apache) has become very popular among developers and web designers, and for good reason. As a programming language, it is particularly suited to web development projects, while being relatively easy to write, use and learn. More importantly, it's open-source and free, cross-platform, and widely supported. David Sklar's Learning PHP5 is one of the latest volumes dealing with PHP. It describes itself as 'a Pain-Free Introduction to Building Interactive Web Sites,' and provides a gentle introduction to the latest version of PHP, which is version 5 and only recently available." Read on for Suda's review.

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.

Sorry! There are no comments related to the filter you selected.

IN SOVIET RUSSIA... (-1, Offtopic)

Anonymous Coward | more than 9 years ago | (#10657906)

...PHP5 learns YOU!

Re:IN SOVIET RUSSIA... (-1, Offtopic)

stevo3232 (794498) | more than 9 years ago | (#10657934)

..and on Slashdot, the first post not being a "oh you suczzz i gotz FIRST POST" is a miracle! Wow. A non-first-postish first post.

THREE MORE DAYS! (-1, Offtopic)

stratjakt (596332) | more than 9 years ago | (#10657913)

Three more days till Hallowe'en!
Hallowe'en, Hallowe'en!

Three more days till Hallowe'en!
SILVER SHAMROCK!

but (-1, Flamebait)

Anonymous Coward | more than 9 years ago | (#10657919)

Python > PHP

=/

Re:but (-1, Troll)

Anonymous Coward | more than 9 years ago | (#10658034)

From a purely language standpoint, yes it does. But from the standpoint of creating web applications, it most certainly does not. Python is slow as hell unless you use mod_php, which is a horrible mess. And then of course python doesn't impliment nearly as many handy web features as php, like sessions, cookies, etc.

Re:but (0, Offtopic)

xoboots (683791) | more than 9 years ago | (#10658120)

Is it my imagination or are the AC's even stupider than usual these days?

HI! (-1, Flamebait)

Anonymous Coward | more than 9 years ago | (#10657920)

I leaked this story early. JEWS DID WTC!

Two free books on PHP (5, Informative)

prostoalex (308614) | more than 9 years ago | (#10657929)

For the beginners it's worth noting that two PHP books are available for free on the Web (outside of PHP.net documentation).

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 (0)

stratjakt (596332) | more than 9 years ago | (#10657949)

Two free books on PHP!
PHP! PHP!

Two free books on PHP!
SILVER SHAMROCK!

Re:Two free books on PHP (0)

Anonymous Coward | more than 9 years ago | (#10658230)

Excellent. I've been looking to learn how to program in PHP but was too cheap to go out and actually purchase something. You've done well young Skywalker.

Re:Two free books on PHP (0)

Anonymous Coward | more than 9 years ago | (#10658581)

Begs the question of whether you consider PHP programming, or just another Highly Touted Masturbation Language (HTML).
Had I no self respect, I would just use ASP again.
One wonders what crayola-ware will eventually replace it...QIQ?

Re:Two free books on PHP (1, Redundant)

Zach978 (98911) | more than 9 years ago | (#10658700)

If you have previous programming experience just go through the PHP Manual [php.net] on their website, that's all you really need if you're trying to pick it up real quick and know how to program.

Dupe.. (0, Troll)

pklinken (773410) | more than 9 years ago | (#10657961)

... when will you guys learn!

I have a bit of a bone to pick. (5, Interesting)

gthumb (826174) | more than 9 years ago | (#10657968)

See, this is a book review of a PHP tutorial book. This is not an excuse for the legions of Perl bigots to run out here and start bashing PHP based on outdated versions and foolish generalisations. You say that PHP isn't ready for enterprise-ready applications, but this is a pretty transparent falsehood. There's nothing inherent in a proper installation of mod_php to prevent a site the size of Slashdot or Google from running with PHP instead of Perl or, G-d forbid, ASP.

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. (0)

Anonymous Coward | more than 9 years ago | (#10658133)

i use perl mostly (sometimes C) and don't care much what anybody else use. i like to stick with perl because i know it very well and it's an awsome all-around language (not just good for web stuff). so because of that i'm not going to learn php but that's because i can already do everything it does with perl. that's not being a bigot, that's just being lazy (or saving my free time to do things other than collect languages).

Re:I have a bit of a bone to pick. (4, Insightful)

eln (21727) | more than 9 years ago | (#10658427)

I've been programming perl for almost 10 years now. 2 years ago, I got a job where the entire codebase was in PHP. Because of my extensive knowledge of perl, I was able to pick up PHP good enough to become one of the top PHP coders on the team within about 2 weeks.

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. (0)

Anonymous Coward | more than 9 years ago | (#10658696)

no zealot is when sombody thinks their favorite language is all that and everybody else should use it. i'm not like that at all. i just don't care what anybody else use to do their stuff, it's their choice and they need to choose what fits their needs.
my needs are quite well filled with perl and C, and learning other language very similar to those doesn't give me enough return on investment for me to put forth the effort. if i find a language that gives me great returns (like say using lisp for doing A.I. coding) then i'll consider how much it's worth, and then make a decision.
btw, the few web stuff i do is nicely handled with CGI.pm for casual stuff, or with mod_perl and the template toolkit for complete control over the environment (or mod_perl with Apache::Registry for in-between stuff). i'm not much into web coding though.

Re:I have a bit of a bone to pick. (1)

Goaway (82658) | more than 9 years ago | (#10658364)

Wow, a little bit defensive, are we?

Re:I have a bit of a bone to pick. (1, Insightful)

Anonymous Coward | more than 9 years ago | (#10658477)

Its version number is the same as Perl
Next time you should leave that part out, it's quite irrelevant and completely superficial.

Re:I have a bit of a bone to pick. (2, Informative)

rainman_bc (735332) | more than 9 years ago | (#10658665)

Woah silver - Have you LOOKED at PHP5 recently? Inheritence, Overrides, Private Methods and properties, static methods. Looks like a pretty good implementation of OOP.

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, which means there's a lot of apps out there for php4 that won't work on a default php5 install. Keep in mind in hosted environments this can be a bit of a problem.

Keep in mind that mysql4-stable doesn't work with imysql yet AFAIK.

I love PHP5, but the lack of default support for the standard mysql package is bad for many existing apps that rely on that package.

(yes the onus is on programmers to get their code updated to something like, oh, adodb maybe?)

Re:I have a bit of a bone to pick. (0)

Anonymous Coward | more than 9 years ago | (#10659144)

Funny, none of us even piped up. Your opinions on OOP are really most telling -- PHP's OO model must really suck...

you are ignorant (0)

Anonymous Coward | more than 9 years ago | (#10659200)

To throw out that "OOP isn't enough of a coherent programming paradigm to be considered a single model or base" is just plain ignorance.

"Overengineering for the vast majority of applications" sounds a bit excessive too!

Have you ever programmed in a real OO language (like Smalltalk for example)?

That being said.. PHP is very good for some things like most web sites.

What does it do differently? (4, Interesting)

colin_n (50370) | more than 9 years ago | (#10657973)

PHP4 is to PHP5 as ASP is to ASP.NET? Is that statement correct? What advances does PHP5 make that puts it in direct competition with ASP.NET?

Re:What does it do differently? (5, Insightful)

ptlis (772434) | more than 9 years ago | (#10657992)

It runs on something other than IIS...

Re:What does it do differently? (1)

ptlis (772434) | more than 9 years ago | (#10658020)

Oh come on, that's not a troll...

Re:What does it do differently? (1)

xoboots (683791) | more than 9 years ago | (#10658091)

Agreed! Particularly in a PHP thread! If I had mod points, you'd get 'em.

ASP.NET and PHP5 explained (5, Informative)

jbellis (142590) | more than 9 years ago | (#10658015)

ASP.NET is infinitely better designed than classic ASP. (Not perfect by any means -- ASP.NET should be next to "leaky abstraction" in the dictionary -- but they got a LOT right this time around.)

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 (1)

Martin Blank (154261) | more than 9 years ago | (#10658213)

How aggressively backwards compatible? It has been my understanding that a LOT of stuff written under PHP4 will not work under PHP5 without significant rewrites, and that there are no intentions of adding in that back capability. I have not yet seriously tried using PHP5 as yet largely because of this. Can you clarify?

Re:ASP.NET and PHP5 explained (1)

AC-x (735297) | more than 9 years ago | (#10658301)

Unless you're using certain quirks of PHP4 (that you shouldn't really use if you're following good coding guidelines) then PHP5 is a dropin replacement for PHP4.

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 (1)

justMichael (606509) | more than 9 years ago | (#10658452)

How aggressively backwards compatible? It has been my understanding that a LOT of stuff written under PHP4 will not work under PHP5 without significant rewrites, and that there are no intentions of adding in that back capability. I have not yet seriously tried using PHP5 as yet largely because of this. Can you clarify?
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 your old code. (but I haven't messed with PHP5 yet)

Re:ASP.NET and PHP5 explained (1)

killermookie (708026) | more than 9 years ago | (#10658308)

Parent post might be a bit misinformed. By the way, what does "aggressively backwards compatible" actually mean??

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 though you may need to consult php.net for further information.

static methods suck and are not really OO (0)

Anonymous Coward | more than 9 years ago | (#10659337)

the OO solution is class methods..

Re:What does it do differently? (2, Insightful)

colinramsay (603167) | more than 9 years ago | (#10658168)

Absolutely not. ASP is a scripting language. PHP is a scripting language with string OOP features. ASP.net is a framework for the web, which allows you to use a fully featured OOP language such as C#.

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? (1)

colin_n (50370) | more than 9 years ago | (#10658219)

I have used ASP.net and PHP4. I love PHP4 for my personal page and the simple things that I make but for making web pages that feel less like the web and more like a native program, it seems like asp.net has an edge. Does PHP5 attempt to create some of the framework that makes it possible to work with data without page reloads etc... it seems like this is what ASP.net does differently. To me, when I work with some asp.net apps, you load the page once and everything else works in the background without refreshing the page with every submit

Re:What does it do differently? (1)

FuzzyBad-Mofo (184327) | more than 9 years ago | (#10659202)

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? (2, Informative)

styrotech (136124) | more than 9 years ago | (#10658227)

Absolutely not. ASP is a scripting language. PHP is a scripting language with string OOP features. ASP.net is a framework for the web, which allows you to use a fully featured OOP language such as C#.

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? (1)

Anonymous Coward | more than 9 years ago | (#10658679)

ASP is a scripting language. PHP is a scripting language with strong[?] OOP features.

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? (1)

Foofoobar (318279) | more than 9 years ago | (#10658218)

Objects are no longer called by copying. OObjects are now called by reference.

Re:What does it do differently? (1)

mojogojo (577421) | more than 9 years ago | (#10658742)

I'll address only your first/second question...
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

PHP vs Zope, Pearl vs Python (4, Interesting)

dargaud (518470) | more than 9 years ago | (#10658010)

I had to use Perl for a project some time back. It was quick and dirty and did the job. At the same time I learned python without managing to apply it to the project. I recognized that I liked python better, but perl was faster to implement.

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 (3, Interesting)

jbellis (142590) | more than 9 years ago | (#10658075)

there are more options for python on the web than Zope, which even many pythonistas consider overengineered and even un-pythonic in many ways.

WebWare and Quixote are probably the biggest; another called SnakeSkin was just announced as having reached 1.0 today.

Back in my day... (5, Insightful)

sleighb0y (141660) | more than 9 years ago | (#10658026)

We would learn PHP from the php.net documentation alone!

And we liked it that way!

Re:Back in my day... (0)

Anonymous Coward | more than 9 years ago | (#10658058)

We would learn PHP from the php.net documentation alone!

Back in your day, we would burry the layout of a webapp inside an awfull big c file...

Re:Back in my day... (0)

Anonymous Coward | more than 9 years ago | (#10658500)

Wow, you must be, what, 15?

Re:Back in my day... (1)

pat_trick (218868) | more than 9 years ago | (#10658520)

If by "back in my day" you mean last week, then yes. I learned PHP straight from the php.net documentation alone for a database project I did for class. Worked well enough for me.

Re:Back in my day... (1)

MonkeyCookie (657433) | more than 9 years ago | (#10658521)

Bah! Back in my day there was no documentation!

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... (1)

doctechniqal (516085) | more than 9 years ago | (#10658598)

We didn't even have ones and zeros, we had to make do with capitalized O and lower-case L.

Re:Back in my day... (1)

Kehvarl (812337) | more than 9 years ago | (#10658751)

You youngsters had everything so danged easy with your 'lowercase' letters.

PHP "documentation" is CRAP! (0, Troll)

mfearby (1653) | more than 9 years ago | (#10658577)

How could anybody make sense of what PHP are touting as their "documentation" when it is merely a collection of ramblings from developers who have had all and sundry problems with it over the years.

Give me good, old, Visual Basic documentation any day - at least you have some examples you can make sense of, without having to read (suffer?) through "writing" by people clearly with a limited grasp of the English language.

PS, although I prefer the way Microsoft document their programming languages, I personally much prefer Perl as a language.

Re:PHP "documentation" is CRAP! (0)

Anonymous Coward | more than 9 years ago | (#10658720)

Whoa! Someone actually likes the VB documentation?!?

Maybe then you can explain why "Methods" and "Properties" each have their own sections rather than being under "Objects"? I could never get past how fundamentally dumb this was.

Re:PHP "documentation" is CRAP! (1)

ScytheBlade1 (772156) | more than 9 years ago | (#10658826)

"documentation"? Yes, I'm *sure* that it's all [php.net] with ramblings of the programmers. [php.net]


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.

mod_perl (-1, Offtopic)

Anonymous Coward | more than 9 years ago | (#10658041)

bitches!

PHP or Perl? (-1, Troll)

Anonymous Coward | more than 9 years ago | (#10658062)

Could someone explain me please, why most of people say that PHP is much better than Perl? I am going to write a database application and I am trying to decide what to learn: Perl or PHP? I noticed that some people are trying to advocate niche languages like Ruby, Tcl, Lua and Python, but most of people say either Perl or PHP.

So, whish one is better? Isn't PHP (Personal Home Page) just a simpler version of Perl? Isn't it better to learn real Perl in the long run? I need to start writing some code in February, so I have some time to read, but I don't want to waste it, so I would really appreciate if anyone could point me in the right direction by providing some hints: when Perl is better than PHP and vice versa. Thanks.

Re:PHP or Perl? (0)

Anonymous Coward | more than 9 years ago | (#10658175)

you should learn perl if it fits your needs
ditto with php
don't listen to somebody elses opinion who doesn't know your situation, do the hard work and find out what your needs are.

Re:PHP or Perl? (3, Interesting)

Flaming_cows (798162) | more than 9 years ago | (#10658209)

Er, PHP stands for 'PHP: Hypertext Preproccessor' (gogo recursive acronyms!), not Personal Home Page.

Re:PHP or Perl? (1)

justMichael (606509) | more than 9 years ago | (#10658529)

Er, PHP stands for 'PHP: Hypertext Preproccessor' (gogo recursive acronyms!), not Personal Home Page.
Actually, you are both right [c2.com] .

Re:PHP or Perl? (1)

ScytheBlade1 (772156) | more than 9 years ago | (#10658843)

"right" is relevant. According to the PHP docs [php.net] , only the recursive acronym is correct now.

Re:PHP or Perl? (3, Insightful)

gentoo_moo (679483) | more than 9 years ago | (#10658226)

My first programming was in Perl. It was akward but fun. I switched to PHP about a year after I started Perl. I picked up the basics of PHP in about a week. Perl took me a bit longer (like a month for the fundamentals - but I was a real newbie too). Inside two weeks of geeking on PHP I'd written a service ticket program for my private consulting business, did some freelance web coding for another firm and wrote a small checkbook (quicken clone) to get used to it with MySQL.

After about 3 months of playing with it, I wrote a web-based tracking system that my company uses to manage service calls and billing.

I think you'd probably pick up PHP pretty quickly. Others may say the same about Perl. This is just my humble opinion.

Re:PHP or Perl? (0)

Anonymous Coward | more than 9 years ago | (#10658369)

It is interesting that you say "it (perl) was awkward but fun."

My first language was perl too. I didn't know enough about other languages to know whether perl was awkward or not. I had nothing to compare it to. It never even occured to me that perl could be considered awkward until other "more experieced" coders would characterize it that way. Only then did I start to adopt this bias.

Re:PHP or Perl? (0)

Anonymous Coward | more than 9 years ago | (#10658397)

90 percent of the time you spend learning PHP or Perl will actually be spent learning how to program. It may not feel like it at the time, but whatever language you learn second, you will learn in a tenth the time.

The problem with PHP is that it is ASS SLOW. If your projects are successful, you will eventually find yourself considering whether to purchase super-expensive machines, rewrite it, or spread the load across many servers, etc.

Perl is about 10 times faster. Also, Perl has more libraries and example code available, and thus may give you a more marketable skill.

But C is about 10 to 100 times faster than perl (which is already 10 times faster than PHP). My advice is buy Kernighan and Ritchie's book, print out or buy the GNU C Library manual and examine the examples on safe string handling (asprintf instead of sprintf, for example), and then use Thomas Boutelle's cgic [boutell.com] library to do your web programming. Your stuff will be fast, there is nothing you can't do . . . if you find something PHP does that you like, just look at the PHP source . . . after all it is written in C, so just use whatever library or code they use. Future employers and clients will know you can learn any language, because you know the one that they are all written in.

Re:PHP or Perl? (2, Insightful)

phek (791955) | more than 9 years ago | (#10658614)

Saying perl is 10x faster than PHP is really misleading. Bad PHP may be 10x slower than bad perl, but from my experience good PHP, is just about as fast as good Perl. The thing is PHP just try's to bring over so many functions from other languages, it can be really slow if your using something like the python derived functions. If you try to code PHP like you code C though, PHP tends to be around the same speed as Perl.

Re:PHP or Perl? (0)

Anonymous Coward | more than 9 years ago | (#10658764)

For most applications, the script speed is irrelvant (see Java). 90% of your bottleneck is going to be the database.

Re:PHP or Perl? (2, Insightful)

downward dog (634625) | more than 9 years ago | (#10659294)

Are you really recommending C for web programming (which is 95% of PHP's use)? Unless you're writing Amazon.com, you will spend FAR too long programming and receive little perceivable benefit. PHP is perfect for most web programming; a shopping cart doesn't need to be uber-efficient. Few web apps peg the processor on their server. And if they do, it is not going to be PHP code that will do it -- it will be database or HTTP.

Not saying that C isn't a great language for some things, but it is not a great language for rapid development of complex web applications. :)

Perl will serve you online and off (1, Insightful)

Anonymous Coward | more than 9 years ago | (#10658446)

Perl does more than produce webpages via mod_perl. It is a powerful general purpose scripting language. PHP is not. PHP was built to spit out html and that is what it is good at.

Re:Perl will serve you online and off (1)

phek (791955) | more than 9 years ago | (#10658639)

that may be what php was designed for but as of early php 4, it's been a great all purpose scripting language. I'd say I use the command line interperter way more than I use it for web pages.

Re:PHP or Perl? (3, Interesting)

phek (791955) | more than 9 years ago | (#10658567)

Neither is really better than the other, it's really just a preference. Saying that php is a simpler version of Perl is totally wrong. The two languages are nearly as different as can be while still striving for the same goal (ok maybe not THAT different but they are very different). The style differences between the two happen to remind me of the differences between basic and pascal if you're familiar with either of those.

Some of the reasons I prefer PHP over perl is because it's a lot more similar to C than perl is. Plus, if I remember right with perl, you have to enable execgi in apache for any directory you want to run perl scripts in (something that i'd be very against doing). But probally the main reason me and lots of other people who prefer PHP hate perl is CPAN. CPAN is the perl libraries which you always end up having to update and it can sometimes be a big pain in the ass. The only thing perl has that php doesn't have (that I know of at least) is signal handling, so you can have the code do something if the program receives an INT signal, or any other signal (something you probally wont ever use).

In my own experience, I learned perl just before I discovered php. Neither language was really hard (I had other experience with non web based languages already), but when learning perl something just felt wrong about the style, awkward as another poster put it.

So in conclusion... don't do any web programming whatsoever, it sucks and you'll wish you never did. Theres nothing worse than having some asshole who doesn't know anything about computers come up to you and say "The font seems a little strange". Come on... WTF DOES THAT MEAN?!? So then you go and make their website Teal, Orange and Pink because fuck them, and then they come back complaining about the color now, but the font looks good. I still do use PHP though I just try to not do any web programming with it. Both PHP and Perl are great for some simple programs that are just a little too much for a scripting language like bash.

Re:PHP or Perl? (2, Informative)

Camel Pilot (78781) | more than 9 years ago | (#10658830)

But probally the main reason me and lots of other people who prefer PHP hate perl is CPAN. CPAN is the perl libraries which you always end up having to update and it can sometimes be a big pain in the ass.

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::NeuralNet that provide an amazing amount of functionality in an easy to use interface. CPAN is actually the reason a lot of folks use perl.

Re:PHP or Perl? (1)

phek (791955) | more than 9 years ago | (#10659105)

Yah, but then you run into the issue that any other system that uses this script now has to go install this module. This model of installing modules as needed for a parser is unlike most other languages, and is something most people haven't taken too (based on I haven't seen other languages adopt this). And I agree, the CPAN concept is a leap forward from the "static" libararies of compilers/parsers, but I think it just overly complicates things. Now if there was a CPAN system for other languages where you create binaries, I'd appreciate it much more than for a scripting language.

Re:PHP or Perl? (0)

Anonymous Coward | more than 9 years ago | (#10659178)

> Yah, but then you run into the issue that any other system that uses this script now has to go install this module.

Whereas PHP comes with every module anyone will ever need?

Oh, take a look at Extutils::AutoInstall sometime, which uses a little stub to automatically download, build, install, and use any module from CPAN on first use. You don't even need to install that module, just paste that stub in.

Incidentally, CPAN borrowed its name from CTAN, the Comprehensive TeX Archive Network. Java has JNLP, etc. But you just in the same breath condemned CPAN as "overly complicates" things. Better duckspeak was never quacked.

open-source vs. suitability to task (2, Insightful)

Anonymous Coward | more than 9 years ago | (#10658098)

As a programming language, it is particularly suited to web development projects, while being relatively easy to write, use and learn. More importantly, it's open-source...

So, being open-source is more important than suitability to task?

Re:open-source vs. suitability to task (2, Insightful)

Anonymous Coward | more than 9 years ago | (#10658310)

It is for me.

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 (0)

Anonymous Coward | more than 9 years ago | (#10659232)

Too bad languages can't be open source or closed source. Tool implementations can, but not the language itself. PHP is no more "open source" than C# is.

For those who like this book (1)

doombob (717921) | more than 9 years ago | (#10658106)

Check out this one [amazon.com] as well. I got them both from the local library (amazing that they had them right away) and Beginning PHP5 was a more complete book. I still liked Learning PHP5, but I felt there were things left out. I know the review says that it doesn't go too deep, but I prefer the practical examples in Beginning PHP5.

Re:For those who like this book (0)

Anonymous Coward | more than 9 years ago | (#10659167)

This one [slashdot.org] would seem to be a much better choice if one is looking for a comprehensive book that goes beyond what the book currently under review covers.

honest question here... (3, Insightful)

EZmagz (538905) | more than 9 years ago | (#10658109)

With a language like PHP that has a very active developer community associated with it, why plop down for a book like this when websites like THIS ONE [php.net] exist and give all the documentation that you'd need when learning the language? I realize that it's handy in having a hardcover book to read (hell, I've got my fair share right next to my unemployed ass) and reference...but still.

Just curious.

Re:honest question here... (0)

Anonymous Coward | more than 9 years ago | (#10658121)

Possibly because some people learn better with some vaguely organized process that walks them through some basic coding and then builds on it instead of just giving them "here's all the functions and their definitions, have at it"?

Re:honest question here... (4, Insightful)

ptlis (772434) | more than 9 years ago | (#10658176)

php.net is a wonderful reference, even for people who have only the most rudimentary understanding of how to use php but for a total newbie I can see how it could be very daunting; I personally began my way with php scripting by downloading a few pre-made scipts (for an automagically generated image gallery iirc) and realising that none of the three I had grabbed worked and there were features that if worked I would like from each. So I did the obvious thing and (looking up stuff on php.net) cobbled them together into a working set of scripts; problem with this route (and self-learning in general) when compared to traditional/book learning is that not knowing any better you get into some bad habbits which may (and im my case did) come back to bite you when you're more knowledgable. Additionally in getting something to 'just work' you may kludge together some funky code when there's a much easier way you could have done it if you'd read around the subject... I think i've rambled enough but the jist of it is that php.net is an awesome reference if you can't remember the syntax for something but is far from ideal for a newbie trying to learn the language.

The fast way to learn PHP.... (4, Funny)

Kenja (541830) | more than 9 years ago | (#10658110)

The fastest way to learn PHP is to track down David Sklar and eat his brain, thus gaining all his knowledge and abilities.

No! (1)

temojen (678985) | more than 9 years ago | (#10658350)

Kuru [wikipedia.org] is bad.

Shake a joystick... (1, Funny)

Anonymous Coward | more than 9 years ago | (#10658115)

There are more new books being published about PHP than you can shake a joystick at.

Sure you can. I did it just last week. If you want proof, just look at the police report.

I read it (4, Informative)

Jack9 (11421) | more than 9 years ago | (#10658119)

When this PHP book appeared in Border's Books last week I read through it to make sure I was still up to speed. I've been programming PHP since 2.0 (back when you could go on IRC and talk with Lars). The book is mostly a verbose rehash of select bits from the documentation by a collection of authors. Wow, described it in one sentence. Didnt seem to have anything over the documentation on the PHP website.

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 (1)

Jack9 (11421) | more than 9 years ago | (#10658141)

Most people know Rasmus, but he wasnt as available as Lars even back in 1999 :p

So tell us... (1)

AltGrendel (175092) | more than 9 years ago | (#10658877)

...what book would you recommend?

stuff (0)

Anonymous Coward | more than 9 years ago | (#10658191)

linux sucks! windows rules!

meow (0, Offtopic)

lamery (598414) | more than 9 years ago | (#10658265)

learning php? let's all write a cms! how radically fresh. dissing php? Hey man, fuck off. I defend what little I grasp. php haiku well call me a pizza, and oven like a jew.

Re:meow (-1, Troll)

Anonymous Coward | more than 9 years ago | (#10658315)

open your legs like horny girl
insert php book for great fun
quack upside down with flying moon

Help is on the way... (0, Troll)

CatGrep (707480) | more than 9 years ago | (#10658313)

Rails. [rubyonrails.org]
You'll be hearing a lot about it in the coming months.

Re:Help is on the way... (2, Informative)

GnuVince (623231) | more than 9 years ago | (#10658383)

I agree! I recently started playing with Rails, and man it's the funnest thing to build web-based applications! It's easy, fun, simple (you have less code in your controller than some frameowkrs have just for their XML configuration files) and it works very well and very naturally!

Joystick? mysql? (0)

Anonymous Coward | more than 9 years ago | (#10658328)

Sigh...some people just never get it.

PHP to ASP (-1, Flamebait)

Anonymous Coward | more than 9 years ago | (#10658329)

I've got a large application written in PHP and need to migrate it to ASP for the stability and widespread platform support. Does this book help with this? I really haate PHP and want to get back to my stable Windows/ASP environment (easier to push buttons).

Re:PHP to ASP (0)

Anonymous Coward | more than 9 years ago | (#10658380)

not FLAMEBAIT, sarcasm

php rocks (1)

opweirdisntit (780341) | more than 9 years ago | (#10658414)

i love php, ive been programming using php for at least 3 years now and no concerns. It rocks as a web dev language and there are so many cool things you can do with it! Even windows programming (GTK :))

Lots of PHP Book Reviews (1)

MonkeyCookie (657433) | more than 9 years ago | (#10658478)

What's with all the PHP book reviews recently? I seem to recall seeing three reviews within the last several months for various PHP books.

They must be publishing these things like mad.

BivTch (-1, Flamebait)

Anonymous Coward | more than 9 years ago | (#10658633)

Talk to o8e of the Have the energy 1. Therefore there You don't need to standpoint, I don't *BSD but FreeBSD say I'm packing OpenBSD leader Theo Butts are exposed (7000+1400+700)*4 our ability to right now. I tried, I don't want to myself. This isn't PERCENT OF THE *BSD NetBSD user Best. Individuals Big deal. Death Windows, SUN or according tothis TCP/IP stack has The Cathedral Are you a NIGGER outreach are BUWLA, or BSD ACHIEVE ANY OF THE I have a life to states that there Join GNAA (GAY volume of NetBSD Departures of Market share. Red been many, not the SLING you can BSD managed to make what we've known Facft there won't hear you. Also, if things the right RAM) for about 20 users. BSD/OS am protesting words, don't get *BSD but FreeBSD see. The number rotting corpse politics openly. I see the same things in be 'very poorly

Coming from a background in Bash (1)

Mr. Flibble (12943) | more than 9 years ago | (#10658806)

I like this book, I picked it up the other week as my new job requires me to work with PHP. 90% of my prior work was all in bash with occasional touches of perl or C.

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 been shocked when he followed the examples in the book and first wrote "Hello, world!" in perl.

Everyone has to start somewhere, and this book is geared to be easy from the start. I certanly don't feel like starting PHP by picking up the cookbook first. Will I read it? Sure - but not until I have finished the beginner books.

Re:Coming from a background in Bash (0)

Anonymous Coward | more than 9 years ago | (#10659162)

> Hell, even John Carmack bought the "Camel Book" when he needed to learn perl

He's probably still not a perl whiz ... Doom's not exactly written in perl, yunno...

I have the book! (1)

InnerPhalanx (783564) | more than 9 years ago | (#10658890)

Great book, I'm new to dynamic Website creation and the book presents information in such a way I or a more experienced person could both equally understand it. Each chapter has evaluation questions at the end. Good stuff, amazed it made it to /.! Also, the hawk on the book is cool too. =)

PHP vs asp.net (0)

Anonymous Coward | more than 9 years ago | (#10659065)

I've done development in both asp and asp.net. I have never even touched a piece of php code. I'm curious ... What are some advantages of php and why should I use it vs asp(net)?

Since there are always (at least) two sides to a story ... disadvantages of php are welcome as well.

Job Lobby (2, Insightful)

Line_Fault (247536) | more than 9 years ago | (#10659153)

I love PHP5! I've been running it since the first beta!
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.

PHP - poor design (0, Troll)

TardisX (15222) | more than 9 years ago | (#10659206)

Disclaimer - I am a perl programmer. However I have my own issues with Perl as well.

But to the point - PHP. When I am forced to use PHP for something, I am constantly amazed at the poor design and horrific bloat of the language.

Case in point - there are no less than eleven different sort routines:

  • array_multisort
  • arsort
  • asort
  • ksort
  • natcasesort
  • natsort
  • rsort
  • sort
  • uasort
  • uksort
  • usort

In contrast, perl has a single 'sort' function.

One might think that having all these different routines might make it easier to perform a custom sort. Nothing further from the truth - in the end for my fairly trivial sorting exercise I had to revert to using the 'uksort' to sort by a user-defined function - but doing that is far more kludgy than in perl anyway (the sort procedure can't be defined inline).

Consistently, people who tell me that PHP is 'easy to use' have never used any other language.

Also consistently, people I talk to who use PHP after having used another language are universally scornful of PHP.

Load More Comments
Slashdot Login

Need an Account?

Forgot your password?