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!

The PHP Anthology 2nd Edition

samzenpus posted more than 6 years ago | from the read-all-about-it dept.

Book Reviews 80

Michael J. Ross writes "When veteran PHP developers have specific and nontrivial functionality that they want to implement in their code, they can do so from scratch, but this can be time-consuming or essentially reinventing the wheel. They can adopt completed code posted in an online discussion forum, but such code tends to be buggy. They can use an open source library or other packaged code, but this approach can oftentimes prove to be overkill. Consequently, many developers prefer focused solutions found in PHP cookbooks, such as The PHP Anthology: 101 Essential Tips, Tricks & Hacks." Read on for the rest of Michael's review.The second edition of this book was published by SitePoint on 23 October 2007, under the ISBNs 0975841998 and 978-0975841990. On the book's Web page, the publisher makes available an overview of the book, links to the authors' sites, chapter descriptions, the table of contents, the index, editorial and customer reviews, the book's sample code, and errata (there are none as of this writing). In addition, there is a link for downloading three sample chapters (2, 10, and 11), in PDF format. The pop-up window for entering an e-mail address for receiving the download link, also gives one a chance to subscribe to SitePoint's Web development newsletters.

All of the authors of The PHP Anthology — Davey Shafik, Matthew O'Phinney, Ligaya Turmelle, Harry Fuecks, and Ben Balbo — appear to have plenty of experience with the language, and probably also have spent time interacting with other PHP programmers in online forums, including SitePoint's own PHP forum. Experience reading the questions posted by programmers of all skill levels, and especially trying to answer them, can give anyone a better understanding of what are the most common challenges encountered by the typical PHP coder. In the book's preface, the authors note that, for choosing the particular problems for their book, they chose ones frequently seen in the SitePoint forum, which is likely representative of all active PHP forums.

This new edition of the book has been updated for PHP version 5, including PHP's major improvements to its implementation of classes and objects, among other aspects of the language. It is one of a growing number of PHP books that depart from the traditional tutorial and reference formats, and is instead written in the increasingly popular "cookbook style." Each section presents first a common problem that Web programmers often encounter, followed by generally complete source code that solves the problem, and commentary that explains the overall solution, along with special considerations that the programmer should watch out for in adapting the given source code to their own situation.

As seen in the majority of cookbook-style programming books, this one groups the problem-and-solution sections into chapters, of which there are 13: an introduction; working with databases using the PHP Data Objects (PDO) extension; strings; dates and times; forms, tables, and clean URLs; files; e-mail; digital images; error handling; access control; client- and server-side caching; XML and Web services; PHP coding best practices. In addition to the preface and index, the book also has four appendices: configuring PHP; a checklist for choosing a Web hosting service; a security checklist; and working with the PHP Extension and Application Repository (PEAR). In total, the book is 542 pages long, and yet it is not visually overwhelming, partly because of the large and readable font chosen by the publisher, as well as the innumerable code snippets and browser screen shots interspersed throughout the narrative.

The primary strength of this book is the significant amount of information provided to the reader, in the form of summaries of critical Web programming problems, working PHP code that addresses those problems, discussion as to why each particular approach was taken, and occasional asides that warn the reader about special difficulties that they might encounter as they implement the solutions within their own development environments and for their own projects. Some of the material may be of little interest to the average reader — such as the chapters on PDO and XML — but most of the material would be of interest and benefit to any conscientious PHP programmer. The chapters on error handling and access control are alone worth the price of the book.

However, this second edition of the book has some weaknesses that may or may not have been introduced since the first edition (which was not readily available for comparison). But none of them are overwhelming or unfixable. Firstly, a reader hoping for a well-edited book will likely become distrustful by the authors' misuse of the term "that" in place of "who." Secondly, there are far too many ambiguous comments in the first-person, e.g., "I would dare to say that..." In a book written by five authors, the reader naturally has no idea who is speaking. Thirdly, there is a fair amount of inconsistency in the formatting of the code throughout the book, including indentation and other spacing, as well as variable naming. Also, every instance of a "{" on its own line (presumably to line up vertically with the corresponding "}"), is an antiquated waste of space, since any decent programmer's editor or integrated development environment (IDE) can do brace matching automatically.

Lastly, almost all of the section titles begin with the phrase "How do I." That is fine within the body of the book, at the beginning of every section. But when dozens of these section titles are listed together in the table of contents, that phrase could be excised so each section's topic would be faster to spot, and there would be fewer unnecessary words. In fact, the section titles don't necessarily have to be posed as questions. For instance, "Using Sessions" would be just as clear as "How do I use sessions?" and faster to read.

It should be noted that this book is best suited for intermediate to advanced PHP programmers, who will certainly get the most out of it. A programmer new to PHP, who would like to begin learning the language, should start with any one of the many tutorial-style PHP books available.

For readers who prefer the portability or environmental benefits of e-books, a PDF version of The PHP Anthology is available from the publisher, on the aforesaid Web page. Any programmer who is — or anticipates — doing PHP work away from their print technical library, should definitely consider obtaining the e-book, which thus can be added to their laptop's development environment, and be readily available for quick reference. The e-book contains all of the content of the print version. It also makes good use of color, for screenshots and other illustrations, as well as using a blue background for the sample code, which is a bit easier to read than the gray used in the print version.

Overall, this new edition of The PHP Anthology offers practical solutions to many common PHP problems, clear explanations of those solutions, and working code — in print and online — that can be quickly used as is or modified as needed. PHP developers should find this book an informative and valuable part of their technical library.

Michael J. Ross is a Web developer, writer, and freelance editor.

You can purchase The PHP Anthology: 101 Essential Tips, Tricks & Hacks, 2nd Edition from amazon.com. Slashdot welcomes readers' book reviews -- to see your own review here, read the book review guidelines, then visit the submission page.

cancel ×

80 comments

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

Don't trust the review (-1, Troll)

Therapist of Slashdo (1195429) | more than 6 years ago | (#21509207)

Just Google it. [google.com]

Re:Don't trust the review (2, Informative)

Anonymous Coward | more than 6 years ago | (#21509251)

Warning, this is a goatse.

Re:Don't trust the review (1)

smitty_one_each (243267) | more than 6 years ago | (#21511595)

Oh, I thought the review concerned PHP, not VB.

Re:Don't trust the review (0)

Anonymous Coward | more than 6 years ago | (#21512233)

Warning, this is a goatse.


The parent is indicating that the gp is a goatse link, not the article itself.

Don't you just love how the slashdot moderation system totally destroys the continuity of any discussion?

If you are going to reply to a post on slashdot you must quote it, otherwise your post will be rendered meaningless by moderators.

Until I viewed this thread at -1 nested I thought you were suggesting that the article itself was a goatse link.

Re:Don't trust the review (1)

timtimtim2000 (884095) | more than 6 years ago | (#21509259)

I'm at work. And seeing the word goatse buried at the end of that link. Not a good idea.

Re:Don't trust the review (1)

timtimtim2000 (884095) | more than 6 years ago | (#21509401)

It has been how many years since tubgirl and we are still dealing with this shit. It hate goatse.

Don't trust the Jew (-1, Troll)

Anonymous Coward | more than 6 years ago | (#21509271)

Google the history [slashdot.org] of the Jew.

Re:Don't trust the Jew (-1, Flamebait)

Anonymous Coward | more than 6 years ago | (#21509387)

Wow, not only are you a fucking jackass, but you didn't even remember the http:/// [http] Nice job!

I've said it before and I'll say it again: (-1, Flamebait)

Anonymous Coward | more than 6 years ago | (#21509329)

PHP: Because 10 million newbies can't be wrong.

Re:I've said it before and I'll say it again: (5, Informative)

corychristison (951993) | more than 6 years ago | (#21509731)

Disclaimer: The opinions expressed in the following comment are of my own. Please do not flame or complain because I do not share the same opinion as you.

PHP is not that bad of a language. Yes, it has it's issues and has brought on it's own stereotype because of it's ease of use. But really, when it comes to getting things done and done quick.. PHP excels very well.

I use PHP on a daily basis. Not just for work (I am a web developer by profession), but for quick dirty hacks (especially when bash is not available) it is great too. I've written entire daemons that watch and entire directory tree (1000+ files) and will alert me in some way of something happens, etc. I've written a IRC-style chat system way back in the day, and so on.

PHP has GTK [php.net] , and apparently QT [php-qt.org] (server appears to be down ATM) bindings now. It has a lot of really useful low-level bindings, such as FAM [php.net] . Along with Sockets and friends PHP is very powerful. Especially if you can get out of the mentality that "PHP was designed for websites." :-)

PHP really has evolved... I am very greatly anticipating the upcoming PHP 6. NAMESPACES! I can't wait.

I've used and worked with Ruby, Python, TCL, etc. etc. PHP just sits right with me.

Re:I've said it before and I'll say it again: (0, Troll)

Anonymous Coward | more than 6 years ago | (#21510225)

PHP is that bad of a language. Anonymous functions? (create_function() is an ugly strap-on and illustrates why PHP sucks). Closures? The brain-dead design of references?

Re:I've said it before and I'll say it again: (1)

nuzak (959558) | more than 6 years ago | (#21511193)

I especially love how running eval() with code that has a syntax error causes the whole interpreter to completely exit. Writing an interactive REPL must be a total bitch.

It's rather like they took perl with all its faults, and stripped off what was left that it actually did right.

why are you using eval? (-1, Troll)

Anonymous Coward | more than 6 years ago | (#21512537)

noob

Re:I've said it before and I'll say it again: (2, Informative)

JewGold (924683) | more than 6 years ago | (#21514299)

try {
                @eval("-=-=-=- INVALID SYNTAX GOES HERE -=-=-=-");
} catch (Exception $e) {}

echo "Yay, I'm still here!!";

Re:I've said it before and I'll say it again: (2, Informative)

Blobule (913778) | more than 6 years ago | (#21514829)

Get with the program please: http://www.php.net/manual/en/function.eval.php [php.net]

Return Values

As of PHP 4, eval() returns NULL unless return is called in the evaluated code, in which case the value passed to return is returned. If there is a parse error in the evaluated code, eval() returns FALSE and execution of the following code continues normally. It is not possible to catch a parse error in eval() using set_error_handler()

Re:I've said it before and I'll say it again: (0)

Anonymous Coward | more than 6 years ago | (#21510675)

I am a web developer by profession
And I used to work in military intelligence before I became a customer care representative at a bank.

Re:I've said it before and I'll say it again: (1)

hpoul (219387) | more than 6 years ago | (#21511203)

(my disclaimer.. don't take it too seriously ..)

PHP is not that bad of a language. Yes, it has it's issues and has brought on it's own stereotype because of it's ease of use.
so.. PHP is not bad, PHP developers are ..

but for quick dirty hacks (especially when bash is not available) it is great too. I've written entire daemons that watch and entire directory tree (1000+ files)
you might want to try perl .. i think in generally .. PHP should have been a template language for perl .. that would have made a great addition .. (if you take out all those pseudo database functions)

I've used and worked with Ruby, Python, TCL, etc. etc. PHP just sits right with me.
i have also used those (and perl,c,java, blah, blah) .. and i see no reason why i would ever use PHP if i'm not forced to ;)

I am very greatly anticipating the upcoming PHP 6. NAMESPACES! I can't wait.
are you sarcastic ?

Re:I've said it before and I'll say it again: (1)

nuzak (959558) | more than 6 years ago | (#21511271)

> PHP should have been a template language for perl

It was a template language for perl, originally.

Re:I've said it before and I'll say it again: (1)

hpoul (219387) | more than 6 years ago | (#21511519)

well .. i knew an early version was implemented in perl because the author thought he needed something simpler..
didn't know it was actually used as a template engine... ever..

Re:I've said it before and I'll say it again: (1)

cerberusss (660701) | more than 6 years ago | (#21512487)

I seriously use Perl on a daily basis in my regular job, but for freelance stuff no Perl is to be seen in a 100 mile radius. It's PHP everywhere.

Re:I've said it before and I'll say it again: (2, Funny)

A beautiful mind (821714) | more than 6 years ago | (#21512665)

Whoa, so it's true. There IS a masochist district in Amsterdam!

Re:I've said it before and I'll say it again: (1)

cerberusss (660701) | more than 6 years ago | (#21515305)

Yep! And the mistress keeps whippin' until the Perl coders can see the raw bytecode in the already obfuscated scripts!

Re:I've said it before and I'll say it again: (1)

A beautiful mind (821714) | more than 6 years ago | (#21512617)

In operating systems there is a saying that those who do not know Unix will reinvent it, badly.

Among interpreted languages, those who do not know Perl will reinvent it, badly. (Python and Ruby were designed learning from Perl, not by ignoring it, unlike PHP in which case I would say we cannot talk about design.)

PHP is an ugly templating engine. PHP IS for websites.

Yeah, right PHP is easy to use...until you don't know what you're doing and just want to get a website up. Once you need it for something professional, then it gets really REALLY annoying. Inconsistent interface, 2700+ core functions, slow speed, but wait! it will have NAMESPACES finally! Didn't Perl have that since 1998?

Re:I've said it before and I'll say it again: (1)

hotfireball (948064) | more than 6 years ago | (#21512659)

HP really has evolved... I am very greatly anticipating the upcoming PHP 6. NAMESPACES! I can't wait.

Along with the namespaces you will also get a "goto" (http://php6dev.blogspot.com/):

4.2 Adding "goto"

Goto is currently missing in PHP, and although there is a limited use for this construct in some cases it can reduce the amount of code a lot.

Right. We can not redesign paradigm to make stuff easier, but we can add GOTO and COMEFROM! I can't wait. ;-)

Re:I've said it before and I'll say it again: (1)

mcrbids (148650) | more than 6 years ago | (#21513011)

If I hadn't checked the UID of the poster, I'd swear I wrote this.

PHP is a WONDERFUL language for development. It's very flexible, fast, easily developed, and has so many extensions to it you can solve just about anything. And it scales very, very nicely. (I use PHP to process tens of thousands of student records in California - it does the job nicely, reliably, 24x7)

The only difference is that I use PHP4 for just about everything, and haven't made the switch to PHP5, yet. (I have a very, very VERY large code base and all our servers are based on RedHat/CentOS 4, which comes with PHP4)

Since PHP4 is now EOL'd as of this winter, we'll be making the switch to PHP5 probably sometime before next summer if all goes reasonably well...

Re:I've said it before and I'll say it again: (1)

CopaceticOpus (965603) | more than 5 years ago | (#21519663)

Namespaces are expected in PHP 5.3, due in Spring 08. Unfortunately, the way they are designed is more like a package than a namespace. They don't seem to accomplish much that you can't do by naming your classes with a prefix.

For example, say that you have a code library named Robert, which contains a class named Dole. Traditionally you'd define it like this:


class Robert_Dole() { }


With namespaces you'd do this:


namespace Robert;
class Dole() { }


And you'd use the class like this:


use Robert as Bob;

$myBob = new Bob::Dole();


Unfortunately, you can't do this:


use Robert;

$myBob = new Dole();


Perhaps they'll be useful, but to me they're looking like a half-assed effort just so we can say, "yes we have namespaces!"

Re:I've said it before and I'll say it again: (1)

corychristison (951993) | more than 5 years ago | (#21524615)

I really hope they are not a flop.
From what you have described here, it looks like it will allow us to use some form of magic handler/config option to auto-load "modules"... kind of like the other language's "use" functions. While not true namespaces, it would be pretty handy for large CMS's, etc.

My biggest hope is that they use namespaces for all of the major modules such as GTK, even the DB's, and so on... but who knows for sure? :-)

Re:I've said it before and I'll say it again: (1)

CopaceticOpus (965603) | more than 6 years ago | (#21526609)

Well, it's already possible to set up class autoloading. For example, if I use the class Zend_Db_Abstract, the autoloader will go out and include the file Zend/Db/Abstract.php, with no include or require statement needed.

It will still be possible to set up autoloading with modules, but I have yet to see how it will be any better. Hopefully the usefulness will become apparent in time.

Re:I've said it before and I'll say it again: (0)

Anonymous Coward | more than 6 years ago | (#21510055)

I think you meant to say Visual Basic.

Oh, man... (-1, Offtopic)

morgan_greywolf (835522) | more than 6 years ago | (#21509343)

Harry Fuecks
Someone please tell me this is not the guys real name.

Braces on newline argument in book review? (1, Insightful)

Anonymous Coward | more than 6 years ago | (#21509423)

That's like arguing over tabs versus spaces.... of all the things in a book to talk about, whether the code has its braces on the same or newline is as irrelevant as tabs vs. spaces or vi(m) vs. emacs

Re:Braces on newline argument in book review? (1)

pigwin32 (614710) | more than 6 years ago | (#21509743)

Yeah, any decent IDE can do syntax colouring so you can save space by putting more than one statement on the same line, your tabs vs. spaces comment is moot.

Re:Braces on newline argument in book review? (0)

Anonymous Coward | more than 6 years ago | (#21510973)

I agree, this is not the place for that argument. Since he brought it up, not all people look at code in an IDE. In fact, when I get to review other peoples code its usually sent to me via email. Good indenting practices are appreciated by me, and uniformity of braces is important. Syntax highlighting and brace matching are worthless on a B&W printed page. Regardless of your personal preference, please please please make sure that the code you submit to someone else is in a readable format without requiring your favorite authoring tool. This goes for people that love notepad++ and its broken tab saving as well as you "but my ide makes it readable" folks.

Re:Braces on newline argument in book review? (1)

SkelVA (1055970) | more than 5 years ago | (#21520533)

Regarding the claim that different samples were written in different styles:

From page 448-

All the examples in this chapter are written using PEAR coding standards.


So if there are samples not following the style, it's an error and no intended. I personally haven't looked through every single coding example though, so I can't make a claim other than that all the ones I've seen have followed the PEAR standard.

goatse? (-1, Troll)

w.hamra1987 (1193987) | more than 6 years ago | (#21509437)

what the hell is that link up there? what's goatse?

Re:goatse? (0)

Anonymous Coward | more than 6 years ago | (#21509649)

Our hearts are extended to the 17 victims of the recent internet fraud

Online tutorials are better and free. (2, Interesting)

iknownuttin (1099999) | more than 6 years ago | (#21509497)

A programmer new to PHP, who would like to begin learning the language, should start with any one of the many tutorial-style PHP books available.

I disagree. Beginning books are usually large tomes that are anything but concise (Python books from O'Reilly!), take pages to get to the point, and the examples can be difficult to follow.

The free online tutorials are concise, provide links to other tutorials, sometimes even editing boxes where you can experiment with a concept, written better, and they're free! After you're done with your $45 tutorial, it usually becomes a doorstop or something to throw under the cat before (hopefully) she pukes.

Re:Online tutorials are better and free. (1)

larry bagina (561269) | more than 6 years ago | (#21510283)

Online tutorials (especially PHP ones!) tend to promote bad practices such as xss vulnerabilities and sql injection. Unfortunately, plenty of PHP books do as well.

Re:Online tutorials are better and free. (1)

cerberusss (660701) | more than 6 years ago | (#21512445)

That's right on the spot. I've seen several questions on forums where my answer was in the line of "Such-and-such and you may want to google for SQL injection".

Re:Online tutorials are better and free. (1)

billcopc (196330) | more than 6 years ago | (#21513045)

Probably because the great majority of technical writers are not programmers. It's far easier to copy/paste code snippets on the web (preferably non-working), put in a few paragraphs of endless philosophical babble in-between and charge $80 for a thick heavy stack of ignorance.

I find the concept of a "cookbook" rather pointless. When you read a culinary cookbook, you're reading an instruction sheet to make a particular dish; more importantly, you're not learning the fine art of cooking. Similarly, a programming cookbook doesn't make you a better programmer, it just gives you a ready-made solution that unfortunately doesn't compile half the time. If a problem is so common that you would buy a book for it, it probably belongs in a shared library.

Re:Online tutorials are better and free. (2, Informative)

CastrTroy (595695) | more than 6 years ago | (#21510311)

A lot of the free online tutorials don't show best practices though. How many tutorials have you seen for PHP + MySQL where it wasn't shown that you should construct queries by concatenating strings with either not escaping quotes, using your own function (because the author has no clue that a proper function exists), using mysql_escape_string (which is deprecated), or using mysql_real_escape_string. The right answer is that in the majority of cases, people should be using prepared statements, so that they don't have to worry about whether or not they are escaping strings properly. Granted I think a lot of books get this wrong to, but most of the tutorials I've seen on the web are even worse. Most of the tutorials are extremely low quality, and I wouldn't recommend that anybody trust them as a place to learn how to write good code.

To point out how bad tutorial code on the net can get here is a little analogy. I was once looking up how to make a timer in VB.Net go off at a certain clock time, when the only argument is would accept is number of milliseconds until it goes off. I found a number of tutorials on the internet that said I should set it to 1000 milliseconds (1 second), and then just have it go off, check if it's the right time, and proceed if it is. I couldn't find anything on the web that pointed out a better solution, but I know there had to be one. Finally I figured out that if I did TimerRunTime.Subtract(Now).TotalMilliseconds, I would do exactly the thing I was looking for, without having the timer go off every second, and actually using less code.

Re:Online tutorials are better and free. (1)

Splab (574204) | more than 6 years ago | (#21510667)

I don't get why the programmer has to escape strings in the first place.

q.prepare("select something from foo where bar = ?");
q.execute(['foo'])

the database magic should take care of putting in the string/int where it belongs. (Python ish code)

Re:Online tutorials are better and free. (1)

gazbo (517111) | more than 6 years ago | (#21511179)

From the parent:

The right answer is that in the majority of cases, people should be using prepared statements, so that they don't have to worry about whether or not they are escaping strings properly
So...ummm...yeah.

Re:Online tutorials are better and free. (1)

larry bagina (561269) | more than 6 years ago | (#21511223)

Prior to PHP 5 and the PDO (which does work like that), native sql access was done through calls like mysql_query, pg_query, etc. Most databases had functions to prepare a statement with place holders; MySQL didn't. (MySQL 5 does and anyhow PDO fakes it for databases that don't have native support).

You don't get it. And the PHP developers didn't either.

Re:Online tutorials are better and free. (0)

Anonymous Coward | more than 6 years ago | (#21514475)

Regarding the VB.Net timer examples, most of them are probably just written simplistically to demonstrate using timers. However, on Windows (the most likely target for sample VB.Net code) the .Net timer is a wrapper for a system timer, which relies on WM_TIMER messages. WM_TIMER messages are not guaranteed to arrive "on time", and can even end up jumbled together in the event queue, so a common workaround is to decrease the timer interval granularity and perform a test against the clock to achieve a more dependable/accurate result. A more robust approach to accurate event timing is to skip Windows timers and use either the multimedia API or a dedicated timing thread instead.

- T

Re:Online tutorials are better and free. (1)

CastrTroy (595695) | more than 5 years ago | (#21516969)

You're right, my methods I've noticed has many problems, with the timer even not firing exactly when it's supposed to. However, I was just looking for a way to run a job at, for instance, 6 AM tomorrow. Usually it's within 5 minutes, and that's accurate enough. I doesn't matter that the job runs exactly at 6 AM, but that it runs around that time, and every day. Most of the posts recommending to go off every second, didn't do so because over a long period the timer was inaccurate, but simply because the writers didn't know how to calculate the number of milliseconds until the desired time. So instead of taking 20 minutes to figure it out, they use this little hack. Also, it seems kind of buggy to me, to have the timer go off every second, and then check if it's the right time, especially if the timer is so inaccurate. If it's 5:59:59 AM when the timer goes off, and then you check, it's not time yet. However, if the next time the timer goes off is 6:00:00 AM, but the computer is busy doing something else, you may not actually process the event until 6:00:01, where you would end up missing it completely. So you end up trying to check within a range, and then also have to worry about recording whether or not it already ran, so you don't accidentally run it twice.

Re:Online tutorials are better and free. (1)

rkcth (262028) | more than 6 years ago | (#21510581)

Umm, why do you hope your cat pukes?

Reinventing the wheel (4, Insightful)

bhmit1 (2270) | more than 6 years ago | (#21509501)

I forgot the source of this one, but it helps put things in perspective:

If no one ever reinvented the wheel, we'd be rolling around on stone tires now.

Re:Reinventing the wheel (1)

s4m7 (519684) | more than 6 years ago | (#21509567)

I've got my own variation of this, which i think is original

avoid reinventing the wheel if you can, but sometimes you don't need wheels, you need tank treads or an airscrew.

Re:Reinventing the wheel (1)

herve_masson (104332) | more than 6 years ago | (#21515405)

> If no one ever reinvented the wheel, we'd be rolling around on stone tires now.

The problem is that php reinvented the stone tires !

Re:Reinventing the wheel (0)

Anonymous Coward | more than 5 years ago | (#21516639)

I have seeing lies summed up in pithy statements like this.

You mean if no-one had improved the wheel we'd all be riding around on stone tyres now.

Re:Reinventing the wheel (1)

Joebert (946227) | more than 6 years ago | (#21529697)

I like to think that if we didn't spend soo much time reinventing the wheel, we'd have flying cars by now.

Rudy Giuliani: Sleazeball +1, Informative (-1, Troll)

Anonymous Coward | more than 6 years ago | (#21509791)

for U.S. Attorney General [politico.com] .

Alternate chapter listing (1, Funny)

Anonymous Coward | more than 6 years ago | (#21509795)

1. How to crash your PHP blog
2. Restoring your software after your PHP blog gets hacked
3. Modifying your PHP blog to have no copyright information
4. Using PHP for SQL injections, part I (of VII)
5. Slowing your website with PHP
6. How to cancel credit cards used with PHP e-commerce systems before identity thieves max them out
7. PHP-driven cross site scripting (in Russian)
8. Using PHP for ray tracing, just kidding, lol
9. Variable spoofing in PHP blogs
10. How to make a living writing about PHP

Forums. (4, Insightful)

onion2k (203094) | more than 6 years ago | (#21509805)

They can adopt completed code posted in an online discussion forum, but such code tends to be buggy.

You what? Discussion forums are full of very helpful, very talented developers. When someone posts some code in one it's seen by many eyes ... it's commented upon, criticised, improved and refactored into a neat package much in the same way as a popular open source project only on a smaller scale. Code from forums is often a very high quality, well tested, and well thought out solution ... plus it can be very specfic to your precise needs if you ask the right questions to get the ball rolling.

The implication of the comment is that a solution from a book is likely to be better code. I've found that not to be the case on several occasions. Bugs are often not caught by technical reviewers.

I'd much rather use a forum solution than a book.

Disclaimers: I'm a moderator on a large PHP forum.

Re:Forums. (0)

Anonymous Coward | more than 6 years ago | (#21510179)

Discussion forums _can_ be very helpful but a lot of times they are not. I have a lot of noobie friends who find code using Google and try to use it. The code is usually from a blog or forum and is often outdated or just plain goofy.

A noobie using Google to find code from blogs and forums almost never turns out well.

Re:Forums. (4, Funny)

bigdavex (155746) | more than 6 years ago | (#21510325)

Discussion forums are full of very helpful, very talented developers. When someone posts some code in one it's seen by many eyes ... it's commented upon, criticised, improved and refactored into a neat package much in the same way as a popular open source project only on a smaller scale. Code from forums is often a very high quality, well tested, and well thought out solution ... plus it can be very specfic to your precise needs if you ask the right questions to get the ball rolling.

Right. For instance, I borrowed some code from a forum awhile back. It helped me get promoted to team lead. I'm sure no one will notice.

Re:Forums. (0)

Anonymous Coward | more than 6 years ago | (#21510625)

someone had to say it, glad it wasn't me :) /salute

Re:Forums. (1)

Bogtha (906264) | more than 6 years ago | (#21510745)

Discussion forums are full of very helpful, very talented developers.

Perhaps some are, but every time I've come across a link to somebody posting code in a forum, it's always been full of huge glaring mistakes, security holes, etc. In fact, I can't think of any place I've seen worse code than in forums.

Re:Forums. (1)

statusbar (314703) | more than 6 years ago | (#21511925)

It is not just the forums, it is in the php documentation itself. For instance, the documentation for the 'date()' function on the php.net website [php.net] has the following example code:

mktime(0, 0, 0, date("m") , date("d")+1, date("Y"));

The problem with this example is that the date() function can return a different value every time it is called - because time keeps on ticking (into the future). So this code has a good chance of failing at any midnight, end of month, or end of year.

Many of the contributed posts at the end of that page also make the same mistake.

A few years ago I posted a friendly comment saying that you are better off getting the timestamp once and then manipulating the fields individually instead of calling date with no timestamp repeatedly.

Instead of any rebuttal or comment to my posting, they just deleted it.

It is scary to think of how many websites out there use broken code like this. I hate when example code is flawed. Avoid doing transactions at midnight server time!

--jeffk++

Re:Forums. (0)

Anonymous Coward | more than 5 years ago | (#21518225)

HERE HERE!!

I would have never learned about variable variables without a certain PHP forum that rhymes with "rev head". I might still be using unencrypted GET's to handle username and passwords. I may also have never discovered a lovely email validation class. OH and a really great way to prevent SQL injection.

The review said two things about forums and they really don't jive with one another.

They can adopt completed code posted in an online discussion forum, but such code tends to be buggy.


and

All of the authors of The PHP Anthology... appear to have plenty of experience with the language, and probably also have spent time interacting with other PHP programmers in online forums, including SitePoint's own PHP forum. Experience reading the questions posted by programmers of all skill levels, and especially trying to answer them,


The author of this review first says that code posted to forums in answer to questions is buggy. The author of this review then claims that the authors of this book have extensive experience posting code in forums in answer to their readers questions.

So, is the author of the article claiming that the authors of this book post buggy code to their publishers forum? What am I to infer from that? That the book is full of same said buggy code?

The only books I buy on the topic of programming are the lovely phrasebooks and pocket books that are great reference materials when I need to quickly lookup a syntax for some rarely used function or to check up a reg exp.

Re:Forums. (0)

Anonymous Coward | more than 5 years ago | (#21518821)

> many eyes

attached to tiny brains. There's nothing about groupthink that improves code.

I'd wager over a million eyes have seen WordPress, and that still hasn't stopped it from being a pile of dung.

Ah more thieves (0)

Anonymous Coward | more than 6 years ago | (#21509815)

"They can adopt completed code posted in an online discussion forum,"

No they can't that is stealing see story below.

For newbs (0)

Anonymous Coward | more than 6 years ago | (#21509849)

Judging from the TOC [sitepoint.com] , this book is more suitable for newbies. The rest can surely find this stuff with Google, and a lot easier than by sifting through 542 pages(!) of basic PHP topics.

Chapter 8.9 is about a topic (CAPTCHA's) that could fill a book or 2 of its own, and what's written is likely to be considered obsolete sooner or later. IMHO text like that just isn't worth the dead tree it sits on.

good book (1)

wwmedia (950346) | more than 6 years ago | (#21509881)

the first edition was very solid and taught me alot! especially about OO (or lack of it) in php5

congrats on the new book

That v. Who - the Relative Pronoun Debate (4, Interesting)

SitePoint Editor (1195639) | more than 6 years ago | (#21511609)

Hey Michael,
As the language editor on this SitePoint title, I'm ecstatic to read how much you enjoyed The PHP Anthology, Second Edition, and to note the great rating you gave it!

I noticed that you made an interesting point about the that v. who confusion, and, being an editor (and therefore by necessity also being, though not always correct, a big, fat stickler), I turned to my style guide for clarification. Here at SitePoint, we rely on two AmE style manuals: The Chicago Manual of Style, and, to a lesser degree, The Elements of Style by the venerable Strunk & White.

According to Chicago,

Although "who" refers only to a person... it can be used in the first, second, or third person.
"That" refers to a person, animal, or thing, and can be used in the first, second, or third person.

Thus Chicago indicates that these two usages are equally correct:

The PHP coders who heard the news raced to their own copies of Chicago to double-check the fact.
The PHP coders that heard the news raced to their own copies of Chicago to double-check the fact.

I know this is of small note, but I thought I'd mention it all the same (after all, it's not often that us lowly language editors have anything relevant to post to Slashdot!).

Thanks again for this detailed review of the title,
Georgina
Editor
www.sitepoint.com

Re:That v. Who - the Relative Pronoun Debate (1)

Miniluv (165290) | more than 6 years ago | (#21512003)

I'm curious then since you mentioned both AmE style manuals to which you refer what Strunk and White say on the topic? I'd get my copy but it's at home and sadly I am not.

Re:That v. Who - the Relative Pronoun Debate (1)

cerberusss (660701) | more than 6 years ago | (#21512049)

I know this is of small note, but I thought I'd mention it all the same (after all, it's not often that us lowly language editors have anything relevant to post to Slashdot!).
No, it's not of small note at all. I'm a tech person and appreciate correct usage of language, and I've seen many people with the same preference. In fact, the 'grammar nazi' is a well known type of poster here and although I don't participate in the nitpicking, I like some off-topic discussion about the finer points.

I've tagged you as a 'friend', so any of your future posts get an additional 5 points so they always show up when reading comments (it's a Slashdot feature).

Re:That v. Who - the Relative Pronoun Debate (1)

SitePoint Editor (1195639) | more than 6 years ago | (#21512319)

Miniluv, they're silent on the point! The pronouns section does give examples in which "who" is used to refer to people, and I can't find any examples that use "that" to refer to people, but I can't find an explicit direction. That's why we call on S&W to a lesser degree than Chicago: it's nowhere near as specific or prescriptive (two factors that, when you're not a native AmE speaker, are much appreciated!). cerberusss, thanks for the encouragement :) Now you mention it, I'm pretty sure I've seen the grammar nazi around here before... Georgina

Re:That v. Who - the Relative Pronoun Debate (0)

Anonymous Coward | more than 5 years ago | (#21516899)

The PHP coders who heard the news raced to their own copies of Chicago to double-check the fact.
The PHP coders that heard the news raced to their own copies of Chicago to double-check the fact.


Yup, both are correct. But they are slightly different. You can modify the former (but not the latter) into:

"The PHP coders, who heard the news, raced to [...]"

which expressly does *not* instantiate a subset of PHP coders (unlike your two sentences), but expressly adds information about *all* the PHP coders (referred to previously).

Bear with my parenthesistithis, I'm a Lisp guy :-)

RTFM! (-1, Troll)

Anonymous Coward | more than 6 years ago | (#21511783)

http://www.php.net/docs.php [php.net]

The only book you need. Sheesh, read the fucking manual people.

Good analogy (1)

Schraegstrichpunkt (931443) | more than 6 years ago | (#21512157)

When veteran PHP developers ...

That's a really good analogy! After writing my fair share of PHP code, and trying to make it behave correctly, I consider writing PHP code to be comparable to fighting in a war.

Strange focus in review (1)

saforrest (184929) | more than 6 years ago | (#21512727)

However, this second edition of the book has some weaknesses that may or may not have been introduced since the first edition...

This begins a 160 word paragraph going on about:
- "that" in place of "who"
- ambiguous uses of first-person
- inconsistency in indenting
- excessive whitespace

Are you kidding me? This is the most significant criticism you have of the book? This? Sure, stumbling upon standard high-school essay editing mistakes in a published work is a pain. But geez, summarize it briefly and move on. I nearly fell asleep reading that paragraph. I mean, look the discussion of whitespace:

Also, every instance of a "{" on its own line (presumably to line up vertically with the corresponding "}"), is an antiquated waste of space, since any decent programmer's editor or integrated development environment (IDE) can do brace matching automatically.

In 2007, when reviewing a programming book for a programmer's website, do we really need to say "integrated development environment (IDE)"? Will "IDE" really not suffice?

And someone should do some style editing on the reviewer. Even in high school I would have gotten crucified for beginning three subsequent sentences with "Firstly", "Secondly", and "Thirdly".

Re:Strange focus in review (1)

saforrest (184929) | more than 6 years ago | (#21512783)

Even in high school I would have gotten crucified for beginning three subsequent sentences with "Firstly", "Secondly", and "Thirdly".

"subsequent" should be "successive". I woulda gotten crucified for that too!

Re:Strange focus in review (1)

jacksonj04 (800021) | more than 6 years ago | (#21512939)

Not to mention that I don't care if my IDE can do brace matching, it's a damn reference book so I want to be able to see where things happen in the code without needing to put it into my IDE in order to get nice formatting!

Abridged version. (0)

Anonymous Coward | more than 6 years ago | (#21513413)

Tip #1: Scrap PHP, install perl.
Tip #2-#101: Create 100 subtly different 'Hello World' programs.

You can now use PHP!

{ on their own lines (1)

gbrandt (113294) | more than 5 years ago | (#21518805)

"Also, every instance of a "{" on its own line (presumably to line up vertically with the corresponding "}"), is an antiquated waste of space, since any decent programmer's editor or integrated development environment (IDE) can do brace matching automatically. "


Thats personal taste and has no place in a book review. Remember that you are not the one reading your own code all the time. Clarity helps other programmers understand what you are doing and curly brackets on their own lines helps immensely. gregor

Remember this (0)

Anonymous Coward | more than 5 years ago | (#21521109)

All your namespaces are belong to PHP.

Brace placement? (1)

cbciv (719774) | more than 6 years ago | (#21533429)

Also, every instance of a "{" on its own line (presumably to line up vertically with the corresponding "}"), is an antiquated waste of space, since any decent programmer's editor or integrated development environment (IDE) can do brace matching automatically.
Brace placement religion in a book review? Really? Brace placement, like editor choice, is a matter of taste and personal opinion. If you feel the need to expound on that topic, pop over to comp.lang.php; I'm sure you'll find a nice flame war there.
Check for New Comments
Slashdot Login

Need an Account?

Forgot your password?

Submission Text Formatting Tips

We support a small subset of HTML, namely these tags:

  • b
  • i
  • p
  • br
  • a
  • ol
  • ul
  • li
  • dl
  • dt
  • dd
  • em
  • strong
  • tt
  • blockquote
  • div
  • quote
  • ecode

"ecode" can be used for code snippets, for example:

<ecode>    while(1) { do_something(); } </ecode>