Slashdot Mirror


PHP Cookbook

CEHT writes "Like Tony Williams said in his review on PHP and MySQL Web Development: "PHP and MySQL are probably the most pervasive add-ons to Apache web servers across the web". And I agree with him. PHP is a very powerful scripting language, so developers (not just web developers) can do almost anything with it." Read on to see how well CEHT thinks O'Reilly's PHP Cookbook helps you do that almost everything. PHP Cookbook author David Sklar and Adam Trachtenberg pages 608 publisher O'Reilly rating 9 reviewer Edmond Lau ISBN 1565926811 summary Solutions and examples for PHP programmers.

The approach that the authors use in PHP Cookbook is great. Like most computer books, the authors usually include a summary (in sentence forms) to illustrate what the readers will expect in each chapter. Skalar and Trachtenberg take this even further by including some preliminary (code) examples to explain the general ideas behind each chapters. The examples in the book are self-contained. In most cases, I've found examples to exactly fit my needs -- this makes it one of the better reference books.

Each chapter in the book is divided into multiple sections of Problem / Solution / Discussion with a FAQ style. In each case, a simple description of a problem is followed by a PHP script as the solution. But the meat is actually in the discussions: in-depth details are included here, where the authors also include references, extended ideas, and scripts to inform the readers how much more they can do about the issue.

For example, I was going to add a simple script to my website to parse RSS/RDF files from certain news websites (CNN, Slashdot, ...), and use it as my Mozilla homepage. (Who wouldn't?) This script seems to be simple, but I may make a mistake here and there. As reference, I opened up the book to the section "Parsing XML with SAX." Then I realized the authors already had the script to parse RSS/RDF files in the discussion. Bravo!

For myself, the most useful chapters I found are: Web Basics, Forms, Database Access, and XML. There are also good examples in topics such as security, internationalization, and file processing/management. However, this book does not cover the basics of PHP. If you are a good programmer, you should be able to get away with this using the PHP Manual. A good book to learn PHP is Programming PHP, also by O'Reilly.

Although this book covers a wide range of topics, it does not cover topics like generating PDFs. I would also like to see the authors add one (maybe two) case studies in later editions. That would give the reader a more concrete example of how to combine tricks presented by this book. Other than that, at the price of $39.95 (or $61.95 CAD), this book is a great buy!

Topics

  1. Strings
  2. Numbers
  3. Dates and Times
  4. Arrays
  5. Variables
  6. Functions
  7. Classes and Objects
  8. Web Basics - available online as example chapter
  9. Forms
  10. Database Access
  11. Web Automation
  12. XML
  13. Regular Expressions
  14. Encryption and Security
  15. Graphics
  16. Internationalization and Localization
  17. Internet Services
  18. Files
  19. Directories
  20. Client-Side PHP
  21. PEAR

You can purchase the PHP Cookbook from bn.com. Slashdot welcomes readers' book reviews -- to see your own review here, read the book review guidelines, then visit the submission page.

51 of 238 comments (clear)

  1. PHP Security by leeroybrown · · Score: 5, Interesting

    One thing I would like to see more PHP books do is to cover the various Security problems that are prevalent in many PHP based web applications.

    Don't get me wrong, I find PHP to be the best and friendliest solution for many things, but some of the Security problems could easily be avoided with some common sense security advice.

    1. Re:PHP Security by Albert+Pussyjuice · · Score: 4, Interesting
      You are right - there is a general lack of books which deal with writing very fault tolerant and secure PHP code. Most of the PHP books I've seen in the stores start from the basics and focus on getting a database connection up and running and then doing some simple input/output/db access. I think that while PHP has taken off as a web language, this has hindered development a bit because everyone using PHP keeps running into the same problems and has to recode constantly to work around them.

      Of course, writing secure code isn't specific to a language and any book on writing secure code should help to pave the way to avoid common mistakes, just substitute PHP for language X. For instance Writing Secure Code by Michael Howard could be a good companion book to any programmer's library.

      Hopefully, in a few years PHP will have a large enough installed user base (as I think it already does) that the advances issues such as security, tolerance, etc. will be dealt with in entire book(s). Can you tell I am a PHP afficianado?

      --
      DID YOUR MOM SERVE YOU AN EXTRA HELPING OF DUMB TONIGHT?
    2. Re:PHP Security by cyt0plas · · Score: 4, Insightful

      The security problems usually aren't the problems of php, it's the developer's problems. PHP is one of the most newbie friendly web development languages out there. For heaven's sake, it even escapes user inputted strings FOR YOU. That stops most sql exploits, shell string exploits at the door. What happens is that some newbie who hasn't taken the time to read the documentation does something dumb like include($_GET['filename']); While this is a exploitable situation, how many CGIs have been exploited because the author failed to strip/escape user input?

      PHP has a couple of common mistakes, but I'm far more apt to trust an inexperienced PHP programmer over an inexperienced Perl programmer, as far as secure code goes.

      --
      Contact Me (got tired of viruses emailing me).
    3. Re:PHP Security by ikewillis · · Score: 2, Informative
      I'm working on a project that aims to solve the matter of keeping database access passwords secure when using PHP as an Apache module (and consequently all PHP scripts must be readable by a single user)

      It's called phpkeychain and it's modelled after the keychain mechanism in OS X.

  2. YES!!! by SuperDuG · · Score: 4, Funny
    Please continue to make these books, I would love to "quit passing on my knowledge" to the morons around me!!

    In all seriousness I enjoy PHP because it is pretty self explanatory, and it can use plain old html inside it too. It's just nice to use a scripting language for the web that was made for webpages originally, not a language that was created for ...

    ... does anyone really know the original intent of perl? I guess that's like trying to find the oringal intent for ducK tape (and no, don't say to seal off ventilation ducts, coz that's what they'd have you believe.)?

    --
    Ignore the "p2p is theft" trolls, they're just uninformed
    1. Re:YES!!! by maharg · · Score: 2, Funny

      Practical Extraction and Report Language

      OR

      Pathologically Electic Rubbish Lister

      --

      $ strings FTP.EXE | grep Copyright
      @(#) Copyright (c) 1983 The Regents of the University of California.
    2. Re:YES!!! by Surak · · Score: 4, Informative

      ... does anyone really know the original intent of perl? I guess that's like trying to find the oringal intent for ducK tape (and no, don't say to seal off ventilation ducts, coz that's what they'd have you believe.)?

      Duck tape was invented during WWII by Johnson+Johnson for the purpose keeping water out of ammunition cases -- it was relatively waterproof, hence the reason people in the military started calling it "duck tape."

      You should try watching the History Channel more often. ;)

    3. Re:YES!!! by Photon+Ghoul · · Score: 2, Funny

      of course Perl can do all that and it doesn't need_a_function_for_everything() to accomplish it either

      No, it just needs a module_for_everything.pm :)

  3. Another book with similar title by bloxnet · · Score: 5, Informative

    Not to be confused with "PHP Developer's Cookbook" (ISBN: 0672323257 - Publisher: Pearson Education) which is a very well regarded reference for PHP. Just wanted to avoid confusion and suggest the book at the same time. There seems to be a flood of PHP/MySQL books out there, or people are just getting around to reviewing them....not sure.

  4. Re:PDFs? by Mr+Guy · · Score: 2, Informative

    Also, someone could bring this up, but I'd still like an answer. Isn't PDF owned by Adobe?

  5. Student Suspended Over Suspected Use of PHP by Anonymous Coward · · Score: 3, Funny
    Topeka, KS - High school sophomore Brett Tyson was suspended today after teachers learned he may be using PHP.

    "A teacher overheard him say that he was using PHP, and as part of our Zero-Tolerance policy against drug use, he was immediately suspended. No questions asked," said Principal Clyde Thurlow. "We're not quite sure what PHP is, but we suspect it may be a derivative of PCP, or maybe a new designer drug like GHB."

    Parents are frightened by the discovery of this new menace in their children's school, and are demanding the school do something. "We heard that he found out about PHP at school on the internet. There may even be a PHP web ring operating on school grounds," said irate parent Carol Blessing. "School is supposed to be teaching our kids how to read and write. Not about dangerous drugs like PHP."

    In response to parental demands the school has reconfigured its internet WatchDog software to block access to all internet sites mentioning PHP. Officials say this should prevent any other students from falling prey like Brett Tyson did. They have also stepped up locker searches and brought in drug sniffing dogs.

    Interviews with students suggested that PHP use is wide spread around the school, but is particularly concentrated in the geeky nerd population. When contacted by BBspot.com, Brett Tyson said, "I don't know what the hell is going on dude, but this suspension gives me more time for fraggin'. Yee haw!"

    PHP is a hypertext preprocessor, which sounds very dangerous. It is believed that many users started by using Perl and moved on to the more powerful PHP. For more information on how to recognize if your child may be using PHP please visit http://www.php.net.

  6. Re:PDFs? by Anonymous Coward · · Score: 5, Informative

    From the adobe website:
    "An open file format specification, PDF is available to anyone who wants to develop tools to create, view, or manipulate PDF documents."

  7. Buy a Book v.s Web Resources by leeroybrown · · Score: 5, Insightful

    I've been doing PHP web development on and off for a couple of years now and I've always found that it's greatest strength has been the availability of very god online resources.

    PHP.net and many other excellent resources are only a browser click away and remain up to date for free. PHP is one of those areas where I'll save my money and buy a book I'll get genuine reference use from.

    1. Re:Buy a Book v.s Web Resources by elmegil · · Score: 2, Insightful

      Nothing like having half a dozen browser windows/tabs open at the same time, trying to fix/write your web page app. Give me a book any time, realspace makes it a lot more convenient to arrange references around me, IMNSHO. That said, I do appreciate the web references, they're good backfill when nothing else seems to solve the problem. Most of the time. Sometimes googling for answers is like finding a needle in a haystack.

      --
      7 November 2006: The day Americans realized corruption and incompetence weren't addressing 11 September 2001
  8. Re:PDFs? by Anonymous Coward · · Score: 3, Informative

    Here's what I use http://www.fpdf.org/ It's a steep learning curve, but it works

  9. No, PDF is open... by SlashChick · · Score: 4, Informative

    The actual document specification for PDF is open. Adobe just happened to not only create the format, but also make the most popular PDF reader and writer (the Acrobat series.) There are, however, free alternatives such as Ghostscript that generate great PDFs from a Postscript file (which you can generate from any program in Windows just by checking the "Print to File" box on a Postscript printer.)

    If you're interested in generating PDFs from PHP, there are a myriad of options available by searching Google. Some web hosting companies also support generating PDFs from PHP, which makes generating PDFs a cinch.

    HTH!

  10. Re:PDFs? by holovaty · · Score: 3, Informative

    Yes, it's completely possible, as long as your version of PHP has pdflib [http://pdflib.com/] installed as a module or compiled in.

    And, yes, it appears to be legal. (It better be, considering I use it at my job.)

  11. The Cookbooks are wonderful! by Utoxin · · Score: 2, Insightful

    I've got the Perl cookbook, and have used many of the source code samples found inside in my work. However, most of the development I do is PHP, and I'm extremely excited to hear that they've released a cookbook for PHP. I reccomend this and the Perl cookbook to any developer who wants advice or inspiration.

    --
    Matthew Walker
    http://www.tweeterdiet.com/ - My Diet Tracking Tool
  12. Re:More PHP by cyt0plas · · Score: 4, Interesting

    /. itself may not be, but PhpSlash is. Also, I suspect the reason the slashdot crowd likes PHP so much is due to (among other things) a couple of reasons:

    1 - It lets you mix html and code in. Sure, it's not the only language that lets you do it, but it's still a strength.
    2 - It's free, open source (zend crap excluded)
    3 - Microsoft hates it. That's always a plus.
    4 - It's increadibly flexible and forgiving. Coming from a c background, this is one of it's most useful features to me. As far as I can tell, most programmers are inherantly lazy; They don't want to work harder than necessary to do a good job. In PHP, types are incredibly loose. If you want to use a string as a integer, a float, and a string all in the same line, you don't have to cast it. It just does it, and the incredibly vast majority of the time, it does just how you expected it to. Why can't C be that smart?

    --
    Contact Me (got tired of viruses emailing me).
  13. Things PHP is missing by Anonymous Coward · · Score: 4, Insightful

    1) consistant database integration - Why not have a SetDBType() function, rather than hardcoding mysql_connect, mssql_connect, myodbc_connect, pgqsl_connect, etc?

    2) Native XML support - It's just not there? Why re-invent the wheel each time? Give us a good XML tree-walking engine DAMMIT!

    3) sane and consistant functions. Single quotes, double quotes, some functions work with both, some work with one or the other, embedded html in an echo screws up if you don't double quote it, etc.

    4) .NET support?

    In short, PHP is a good language for small projects, but just doesn't cut it in an enterprise setting.

    1. Re:Things PHP is missing by tkiehne · · Score: 2, Informative

      The PEAR packages, usually bundled with the distribution, would take care of the first two:
      http://pear.php.net/

      --
      -- t_kiehne
    2. Re:Things PHP is missing by weston · · Score: 4, Informative

      1) consistant database integration - Why not have a SetDBType() function, rather than hardcoding mysql_connect, mssql_connect, myodbc_connect, pgqsl_connect, etc?

      I believe there is a PEAR package that abstracts an OO layer over the functions to various databases. Think DBI for PHP.

      2) Native XML support - It's just not there? Why re-invent the wheel each time? Give us a good XML tree-walking engine DAMMIT!

      Natvie XML support is there. A SAX parser is usually built in by default. I'm happily using a DOM XML interface that I compiled into my version.

      3) sane and consistant functions. Single quotes, double quotes, some functions work with both, some work with one or the other, embedded html in an echo screws up if you don't double quote it, etc.

      Quotes in PHP do work in a sane and consistent way, very similar to the way they work in PERL. The only thing I mourn is the lack of a qq[-like facility (and I wouldn't be surprised if someone snuck it in while I wasn't looking, and I just didn't know about it).

      4) .NET support?

      Um.... why?

    3. Re:Things PHP is missing by Angry+White+Guy · · Score: 2, Informative

      It's also on the query side as well. How many people have written wrapper classes to deal with different databases?

      As a side effect, implementing one database call, even with a db_type parameter in the database calls, gives a certain level of abstraction which would allow for greater cross portability. It also helps with application debugging, generating the error closer to the actual failure point, rather than in the wrapper class itself.

      --
      You think that I'm crazy, you should see this guy!
  14. Sick and tired of this by aardwolf204 · · Score: 2, Insightful


    I'm a PHP/MySQL junkie, and every time I see anything about PHP on /. its a damn book review. I know the dynamic duo (php/mysql) are the hottest things to hit the net since <blink> but could we get some more interesting new on php, how about something on php-gtk, or the various other php related projects.
    </rant>

    --
    Im dreaming ofa big bndwdth, That can resist the /.crowd.May ur days b merry & bright & may al
  15. Good learning tool by mni12 · · Score: 2, Insightful

    I actually bought a copy of this book, as well as the other one referenced in this review. I found them quite useful in learning PHP - the examples can be easily tweaked to create useful little applications. I haven't done very much with web programming except for few CGI-scripts and PHP definitely looks much easier way to create useful applications.

    The examples of integrating to MySQL were especially useful as I have been playing with Microsoft Access using MySQL as server, and now I can easily create web views from the database!

  16. The perfect companion for this book... by jpkunst · · Score: 3, Informative

    ... is (IMHO) the MySQL Cookbook. The 'Cookbook'-format (specific real-world problems and possible solutions) makes for extremely useful books.

    JP

    1. Re:The perfect companion for this book... by MattRog · · Score: 2, Funny

      Because, as we all know, the cookbook approach is the best way to go. :P

      --

      Thanks,
      --
      Matt
  17. News? Publish date = Nov 2002 by walterbyrd · · Score: 2, Insightful

    This book has been out for nearly a year. Is this news?

  18. Re:PDFs? by Kamel+Jockey · · Score: 3, Informative

    Can you generate a PDF with PHP without also generating an Adobe lawsuit?

    There's no liability shield built in, but FPDF is a great tool that can generate PDFs using PHP without the need for using a commercially-licensed (read "expensive") PDF generating library. I like it because it is distributed under a BSD-like license.

    --
    In case of fire, do not use elevator. Use water!
  19. Re:Speaking of FUD by lamz · · Score: 2, Insightful

    Since the "language of browsers" is ECMAscript it makes sense to use that on the server, too, so one doesn't have to constantly shift back and forth between languages.

    That doesn't even remotely make sense. Most browsers have javascript built-in, so that should decide what language to use server-side? Personally, keeping javascript for client-side and PHP or whatever for server-side is less confusing. That contextual switch is easier when the client-side / server-side code looks different.

    Now I'm off to find a review of a Javascript book, so that I can insert random comments about what a shitty little language it is. That will be quite helpful for someone who wants a book about Javascript, I'm sure.

    --

    Mike van Lammeren
    It will challenge your head, your brain, and your mind.

  20. Re:Enough MySQL by Kz · · Score: 2, Informative

    Because it's easy, fast, and 'real' enough for the vast majority of quick webpages.

    just like PHP

    if you want a big, complex, very scalable website; it might be better to go with java, for everything else (>90% of cases, i'm sure) it's easier to do it with PHP.

    just the same; if you want a heavy duty database, with lots of concurrent updates, and/or triggers, stored procedures and so... well you can do it with Postgres or mortgage your house and use Oracle. for everything else, it's easier, quicker; and usually faster to use MySQL

    --
    -Kz-
  21. Excellent book, I heartily recommend it to any... by Naum · · Score: 3, Informative
    ...PHP developer.

    Relevant, real-life useful examples are given and even a seasoned pro like me picked up a few gems like the example user authentication code that utilizes a hash instead of having to go back to the database on each page fetch.

    My bookshelves are full of PHP books but most of them are inferior to the online documentation at php.net. They add nothing and are a true waste of trees. This one, however, does not fall into that category.

    --

    AZspot
  22. Re:Ain't php great? by Christianfreak · · Score: 2, Informative

    It would take a whole lot of perl code to achieve the same functionality that can be accomplished in 200 well-written php code.

    You obviously don't know Perl, at the very least you don't know about CPAN. How about a decent HTML parser for PHP. XML? How about this: write a program that reads an Excel spreadsheet and uploads its content into a database and let me know how long it takes you in PHP.

    PHP sucks because there is no standard way to extend it, and don't mention PEAR as it so poorly documented its almost completely unusable save for a few of the 'modules' that are there.

    Rather than implement proper namespaces the developers chose to throw everything in the core language. Thus you get a_function_for_everything() which sure makes it easy for the web monkeys to memorize it or look it up but never how or why something works, and in the end you get nothing more than an unmaintainable mess. What happens when a new feature is needed. Re-write city (Yes that is a rant because I've had live in the shadow of my web-monkey predecessor).

    Also what's with mixing data and logic? PHP's whole premise is just plain backwards. Just recently are they trying to bolt on some sort of templating.

    Other problems: no access to the web server, difficult to generate web-server response codes. Errors, including full path-names etc are spit out to the user. (great for security).

    Its been my experience in dealing with both PHP and Perl that proper, templated, documented code takes about the same amount of time and code. And with all the hacks to work around the above problems with PHP, its just easier and more maintainable to use Perl. (Too bad my employers don't see it that way)

  23. Re:Speaking of FUD by runderwo · · Score: 2, Informative
    ASP is not a language. PHP is a language (I'm being generous here).
    PHP actually is not a language. PHP is an engine for embedded scripting languages in markup documents. Zend is the scripting language that most people generalize as "PHP", but any other scripting language could also be developed and used with the PHP engine.

    Remember, PHP is to ASP as Zend is to VBScript.

  24. Re:Ain't php great? by Mr+Bill · · Score: 3, Informative
    It would take a whole lot of perl code to achieve the same functionality that can be accomplished in 200 well-written php code. (Depending on what it did - it's based off my personal experiences).

    If that is a challenge, then I accept. I can guarantee you that for every command in PHP, there is an equivalent command (or module) in Perl. Hence you should be able to write this imaginary program in exactly the same number of lines...

    Although perl and cgi scripts can be ran from the command line, they can't have (X)HTML mixed in quite as easily.

    Have a look at Embperl, HTML::Mason, Apache::ASP for a couple of examples of how to do this. Most people who knock perl have never discovered the right tools. Personally I would never use those tools, because I am a strong believer in the separation of Code and HTML. I use a templating system for all my projects, and you will never see one HTML tag in my code. Once you work with a team of developers and a separate team of designers you will understand the need for this separation.

    PHP is a great tool! I have used it for several applications in the past (6 or 7 years ago). But if you think that PHP can do more than perl can then you are mistaken...

  25. All PDF generators suck by Black+Perl · · Score: 2, Insightful

    *Obligatory PHP flame from the Perl Guy *
    Of course unlike Perl there are no easy/good ways to create one in PHP
    */Obligatory PHP flame from the Perl Guy*


    There are no good ways to create one in any language. Current solutions are either:

    (1) A thin shell over text and graphics primitives

    or (2) dependent on an external rendering engine which creates another format like Postscript.

    I'd like a high-level PDF creation library that would let me, say, directly create a table that is sized to fit the contents like HTML, but unlike HTML, will split the table across multiple pages, repeating header and footer information. Sounds straightforward, right? Not possible now. I've checked with Adobe engineers, and it's not even possible with their $20K PDF generation toolkit.

    I can just hear the XSL-FO people saying, "but it IS possible with XSL-FO." And it's also possible, given all the sand and steel you could possibly need, to build a window. Point is, it's currently way too much trouble. I'm sure it'll get there eventually, but PDF creation is really an idea in its infancy right now.

    --
    bp
  26. Re:The superiority of PHP over Perl by lamz · · Score: 3, Informative

    Amen!

    I did a lot of Perl development before switching to PHP, and some of the things you mention that are missing from Perl are readily available as modules from CPAN. But that just adds another point in PHP's favour -- the default install comes with all the stuff you mentioned.

    Before anyone gets their Perl backs up, let me point out why a good default install is important for web development: you don't always have control over the server, so you can't always get the Perl modules you want. (But if you want to re-write your code, sometimes, you'll get what you need! (Couldn't resist.))

    --

    Mike van Lammeren
    It will challenge your head, your brain, and your mind.

  27. Re:Speaking of FUD by Publicus · · Score: 4, Insightful

    So what are you saying is better than PHP? Running ASP with Javascript (or ECMAscript to be pedantic)?

    If you can tell me that handling forms and working with databases can be done better with something other than PHP please do.

    Also, please tell us what is a 'bigger' language, if PHP and *gasp* Perl are so little?

    I wonder because I started in ASP with VBScript. I learned Perl and PHP and now I do PHP pretty much full time. If I want a script that is blantent CGI I use Perl. To me PHP and Perl completely blow away (not blow chunks) ASP with VBScript -- they are far better languages for web development. I can't say exactly why I think that, but one of the main things for me is the quality of the community surrounding the language. There's a lot more user support for PHP and Perl which to me is more helpful than the MSDN library will ever be. I also like a lot of punctuation -- but that's just a personal preference.

    As far as switching back and forth between languages (JavaScript and PHP, for example), I never thought it was so silly. To me, doing things client-side is distinctly different from doing things server-side. It's no problem to have different languages for those two things. Especially when have to limit what you do on the client side because every browser is different. It seems to me like wasted effort to spend to much time on JavaScript stuff, because lo and behold browser X won't support what I'm trying to do. If I do it server side in PHP, I have an easier time writing portable code.

    You certainly have a right to advocate your language of choice, and probably a right to bash others, but could you explain yourself a little better?

    --

    My Karma was at 49, then they switched to words. All that work for nothing!

  28. Re:Hmm by waynetv · · Score: 2, Informative

    PHP has reflection...

    An entire chapter in the manual for it.

  29. I'd give anything by digidave · · Score: 2, Insightful

    to see a book that deals with advanced application design in PHP. The problem with PHP is that most PHP developers are amateurs who don't know the first thing about app design. At best, apps are written with objects used randomly to accomplish some tasks and mostly include files for 2 dozen reused functions (or functions that aren't even reused, but still included in every page).

    At worst, every database connection is hard-coded in a different place and there are no comments anywhere.

    In either case, my God help anyone who wants to add functionality. These same people need a good book on relational database design, or be subjected to 4 years of universigy RDBMS design courses like I was. IMO, if you aren't willing to slit your wrists to get out of an RDBMS design class, you haven't taken enough of them.

    --
    The global economy is a great thing until you feel it locally.
  30. Re:Speaking of FUD by lamz · · Score: 4, Informative

    PHP actually is not a language. PHP is an engine for embedded scripting languages in markup documents. Zend is the scripting language that most people generalize as "PHP", but any other scripting language could also be developed and used with the PHP engine.

    You have that ass-backwards. PHP is the language, Zend, the engine. Any other scripting language could be developed and used with the Zend engine.

    --

    Mike van Lammeren
    It will challenge your head, your brain, and your mind.

  31. Re:Ain't php great? by rmstar · · Score: 2, Funny
    For Web stuff I prefer Common Lisp. Better performance, plus it's a language for grownups.

    rmstar

  32. Re:More PHP by Smidge204 · · Score: 2, Funny

    If you want to use a string as a integer, a float, and a string all in the same line, you don't have to cast it. ... Why can't C be that smart?

    Having a pretty broad background in VisualBasic...

    *puts on asbestos suit and goggles* ...one of the major drawbacks to that is processing overhead. In VB, any variable you don't define is of type "Variant", which is 14 bytes plus the actual data. Ouch. Not to mention the work that has to be done to figure out what the data is and properly deal with it.

    And, of course, making a typo in a variable name can make debugging a real headache. Because you don't have to cast your variables, anything you type is valid, and typos don't generate errors! (You'll always find "Option Explicit" in my VB modules!)

    Having about a month's worth of self-taught PHP behind me, and actually being very comfortable and productive with it, I find that the no-cast variable system works very smoothly. It's a little wierd when it comes to arrays, but good naming conventions help there. It's nice to not have to stop and make a new variable declaration all the time - just code.

    And let's not forget the true power of no-cast variables: obfuscation! He's using it as a flag! No wait.. it's a loop counter! NO! It's an array! AAAHH!! :)
    =Smidge=

  33. 'web apps' by Kunta+Kinte · · Score: 2, Insightful
    One thing I would like to see more PHP books do is to cover the various Security problems that are prevalent in many PHP based web applications.

    I think a large part of the problem is that PHP is illsuited for many of the larger web applications it is being used for. Traditional Application Server features such as tag libraries found in JSP, ColdFusion, etc. would be good for separating the 'coders' from the 'presentation designers' in large projects, but that's not pertinent to security.

    What gets large PHP web applications like web based mail user agents, like Squirrelmail, and content management systems like PHPNuke is that they have to keep a lot of temporary resources between user actions in a single session. Resources such as open files, sockets, variables in memory, for instance.

    PHP's simple engine, and its lack of language features to support these features forces PHP web application developers to build and destroy many of those resources in the life-cycle of the script instead of the life cycle of the application or the user session that is more appropriate.

    The larger the application gets, the more difficult it gets to build using the simple 'web scripts' programming paradigm PHP and Perl pushes developers towards. This affects security and performance.

    The end result is heavy dependence on databases for variable persistance and error-prone algorithm concoctions, a la PHPNuke et. al.

    --
    Based on upvotes, Ageism is the only "-ism" Slashdotters care about and think isn't SJW
  34. What? No OOP fight? by Tablizer · · Score: 2, Funny

    I expected somebody to come in and say, "PHP's object support is not very good and OO and GOF patterns are the savior of code management and mega-reuse and getting dates, etc. etc." But I have not seen that. What's an OO critic to do? :-)

  35. Don't judge PHP/XML yet, look forward to PHP5. by chregu · · Score: 2, Interesting

    PHP 5 will have much much better XML support.

    There is a lot of work on a complete new DOM extension, which should clean up the mess done in domxml as of PHP 4. It will follow the W3C DOM API as much as possible and is completely rewritten from scratch.

    Furthermore Sterling Hughes is working on SimpleXml. An extension which should make it much easier to access XML Documents with the usual PHP functions.

    The SAX Parser in PHP 5 will also be based on libxml2 and not anymore on the aging expat library.

    XML Validation, XPath and XSLT support are also currently revised and should be improved a lot in PHP5.

  36. Definitely Worth the Buy by GreyLurk · · Score: 2, Informative

    I've been using this book for about 3 months, and I'm no Newbie to PHP programming but it's got some invaluable stuff in there.

  37. Re:The superiority of PHP over Perl by namekuseijin · · Score: 2, Interesting

    >>Recently I've had a chance to do some web design with PHP.

    some (?) web design (??)... how much of it to begin with?

    >>Previously I'd used Perl because I'd heard from many people that Perl was the end all and be all of scripting languages for the web. Imagine my suprise to discover that PHP was vastly superior!

    Perhaps your surprise came from the fact that you were using CGI Perl and that PHP was a fast Apache module? You'd be surprised to learn, though, that today there's also a Perl Apache module as well which is as fast or faster than PHP's...

    >>I know this is a bold statement, but I have solid arguements to support it.

    You better have them as we'll see below...

    >>I'm not arguing that PHP is better than Perl in all cases. There is certainly still a use for Perl.

    Actually, it's the contrary: Perl is one of the most flexible and faster high level languages in existence. It is used for nearly any tasks imaginable dealing mostly with character string processing, that is, it's an overall great general purpose Turing machine. PHP for some misterious reason is used solely as a tool for building html pages, or perhaps PDF using some commercial library...

    Besides, you're aware that php was born from Perl, aren't you? They just dumbed it down so as not to scare ex-M$ users away and because of this the language just lost much of its strengh and flexibility. Ever heard of Perl's motto: "There's more than one way to do it"? It means you can express the same computation many different ways. It means, for instance, that you may express in purely procedural fashion or object oriented, where you see fit. In php (and Python as well) you're trapped in OO craze. There's just one way to do things.

    Also, Perl is one of the most compact (and therefore faster) languages in existence. Of course, people's unwillingness to learn the language make them look at features such as "do { print if /anypattern/; } while();" as beyond their comprehension, but it's not the language's fault if they don't wanna use some the languages builtin features for their great advantage...

    So, i say, i'm not saying Perl is better than php in all cases, there's certainly still a use for php... :)

    >>Finally, I'm not the most talented Perl programmer out there.

    That seems obvious!

    >>I generally prefer to use the vastly superior Python, but can use Perl if I have to.

    I like Python too and highly regard it to be Perl's spiritual brother. But i wouldn't say one or the other is better. Though i would take Perl's flexibility and compactness over Python's rigid OO syntax anyday. One thing is true: they both beat the crap out of php and its VB-like stand...

    >>* Ease of use. I would definitely not recommend anyone new to programming begin with Perl.

    I wouldn't say ease of use is one of Perl's deficiencies. But surely the learning curve for the language is kinda steep. Still, power comes at a price and if you are willing to use a powerful tool you'd better learn how to use it and use it well.

    I can say once you learn Perl right, most other languages just feel like lacking in flexibility, expressiveness or compactness.

    Yes, if you never used a katana, you'd better get to grips first with a bamboo stick or something.

    >> * The OO of PHP is excellent. In my experience, it rivals Smalltalk.

    Who do you think you're fooling? PHP's OO features are more like Javascript than Smalltalk, stop daydreaming. If you want high level OO stuff go with Python's multi-inheritance model.

    >>Hopefully Perl will be patched up so it supports such must-have OO features like introspection, reflection, self-replication and ontological data-points.

    When there's real need for such features, yes. Because Perl doesn't force you into OO syntax, many constructs which just make sense in a purely OO view of the world are not really need

    --
    I don't feel like it...
  38. Re:Ain't php great? by raju1kabir · · Score: 2, Insightful
    I can guarantee you that for every command in PHP, there is an equivalent command (or module) in Perl.

    Well, it'll be a module, not a built-in; Perl's built-ins are often powerful in the broad thermonuclear sense, but are never web-specific. Two key differences remain, though.

    One: The Perl modules will have 15 dependencies each, 3 of which are no longer available at CPAN and which have to be hunted down from a Taiwanese mirror using archive.org.

    Two: The various Perl modules you need will use different and incompatible pet data structures as preferred by their various developers, so you'll spend extra time writing glue code - vs PHP where you just use the function and go.

    --
    "Patriotism is your conviction that this country is superior to all other countries because you were born in it." -- GBS
  39. Obligatory Smarty plug by mlas · · Score: 2, Informative

    1 - It lets you mix html and code in. Sure, it's not the only language that lets you do it, but it's still a strength.

    I thought that PHP did a great job of mixing HTML and code until my PHP apps started reaching a certain size. Even using function calls and classes, templates started getting convoluted. Then I discovered Smarty and my whole way of working changed. Smarty is a template manager that allows for more precise separation of content and code. As a super-simple example, lines like become {$variable}. Over the course of a whole site, the savings from this syntax alone ease code readability (yes i care about such a thing). But there's a lot more to smarty than shorter variables, including shorthand for string modifiers and loops, as well as a nifty caching system that can speed up dynamically generated sites, and zillions of other really cool things for "lazy" programmers like me.

    A lot of people on this thread have mentioned AdoDB (my other favorite PHP add-on), but I haven't seen anyone give a proper shout out to Smarty. It's made my life easier.

    --
    "Luck is the residue of design" --Branch Rickey
  40. Re:More PHP by raju1kabir · · Score: 2, Funny
    That is super silly IMO. Other scripting languages have done just fine without "hidden types". I do not like hidden types. I do not like them in the rain, not in a train, and not in my brain, Dear Sam-I-Aim.

    Types aren't hidden in PHP
    As anyone can plainly see
    They are not hidden from your code,
    They're right there from the time you load.
    With gettype() they're revealed to you,
    With *val() you can set them too.
    There's so much flexibility
    I can hardly contain my glee.
    Setting, seeing, casting types,
    PHP answers all your gripes.

    --
    "Patriotism is your conviction that this country is superior to all other countries because you were born in it." -- GBS