Slashdot Mirror


PHP 5 Objects, Patterns and Practice

Daniel Holmes writes "In addition to using PHP to 'just get the job done' for years now, I've been running a humble user group here in the Midwest. As such, I have read numerous books on and around the subject, always looking for something great to inspire my colleagues, group members and myself alike. There are a metric ton of books out there that will walk you through PHP syntax -- this is not one of them. If you are looking for a book on rapidly developing prototype sites, or writing lots of HTML-embedded PHP, just keep looking. But if you have read even one of those books, or just felt like your programming style itself could use a little upgrade, then go get yourself a copy of PHP 5 Objects, Patterns, and Practice by Matt Zandstra." Read on for the rest of Holmes's review. PHP 5 Objects, Patterns and Practice author Matt Zandstra pages 437 publisher Apress rating 10 reviewer Daniel Holmes ISBN 1590593804 summary A powerful tour though PHP 5's object-oriented features; leveraging the power of design patterns and developer best-practices.

For around 40 bucks, you will get a book separated into three main parts, as the title suggests; plus an Introduction, Conclusion and Appendix. However, you also get an amazing level of detail, insight, and plenty of lessons from the (even non-PHP) programming greats. In just over 400 pages I saw hints as well as direct references to some of the best texts in the business: The Pragmatic Programmer, "the GoF", "Enterprise Patterns" and a host more that I will touch on later. The point is: if you have seen true object-oriented development, and have had trouble using these concepts in PHP; don't despair any longer. Matt has done all the work for you--all you need is a weekend or two to do a little reading. Part I - Introduction As you would expect, Part I really sets the stage for the whole book. It points out where the typical state of PHP development is, and (frankly) why we all need to read Matt's book. He does this by telling a great story of a project life cycle gone badly. As many of you know, systems are easy as they are small, but as they grow things often get out of control without proper care and feeding. This section is important as so many good PHP developers don't even know why their code has grown so rapidly out of their control. Don't skip it, even if you know better.

Part II - Objects In Chapter 2, we read the story of the evolution of PHP as a language -- specifically in regards to its object-oriented (OO) constructs. This is nice in that the author presents it in a way so as to not insult the procedural crowd -- something I often struggle with around this topic. Matt's writing style is immediately approachable; he does not come off as the pretentious object-oriented zealot you might expect from the lengthy title.

You also learn that his lessons will take you way beyond just the syntax. Knowing the ins and outs of PHP's oo syntax is not enough: "You must first choose the right participants for your system, and decide the best ways for them to interact." Now that's something you rarely get in a PHP book.

In Chapter 3, we begin to review the new syntax introduced in PHP 5; just to make sure we are all on the same page. One nice feature here is that Matt uses "sidebars" to point out everything that isn't available in PHP 4. This makes it easy to pass over if you are starting with PHP 5, but it also makes the information available for the rest of us.

It is important to note that this chapter gradually and effectively introduces the layers of OO syntax available in PHP 5. Each lesson or feature simply builds on the next. This makes it nice because you can stop, try things out, read some more, etc.

Chapter 4 takes us a little deeper into PHP 5's OO syntax. It is quite helpful that Zandstra breaks up Chapter 3 and Chapter 4. If you are new to OO syntax, the end of Chapter 3 makes a great place to stop and reflect for the night. Seriously, go to bed and let it sink in.

As you can imagine, the "Advanced Features" include concepts such as:
  • Static methods and properties
  • Abstract classes and Interfaces
  • Error handling and Exceptions
  • Final classes and methods
  • Interceptor methods aka "Object overloading"
  • Destructor Methods
  • Object Cloning
  • The magic __toString(): converting objects to strings.


These are not particularly easy topics to master the first time you hear them. However, I think Matt finds a great balance of code and presentation to get the ideas across.

His section on Exceptions alone should be required reading for anyone using PHP 5. Again, not only does he show what they do, he really explains how they will actually help you out.

By the time you get to Chapter 5, you are ready to learn a handful of tips and techniques you can use to keep yourself out of trouble. First off, as PHP is lacking support for true namespaces, Matt shows us the PEAR method of using naming conventions to avoid namespace conflicts. We also learn about using include, require and the new (and possibly controversial) __autoload() function. Of course, there are pitfalls with nearly all of this, and Matt makes sure we know them before we leave the chapter.

Finally he walks us through various reflection techniques. Naturally, starting with simple, function-based reflection. Then taking us through a very complete tour of the new class-based, Reflection API. If you haven't used this, it is a very clean way to expose every nook and cranny of your objects and classes at runtime. Something that can save your sanity in a language that lets you change your API on the fly. Again, it's not just a bunch of talk; there are plenty of great examples to get you there.

By the time you get to Chapter 6, it is time to take another break. Better yet, if this is all new to you stop and play with the code for a bit. Sure you could keep reading, but it will really help if you have the syntax and concepts down so you don't keep flipping back.

Again, Zandstra doesn't just jump straight into design examples; rather, he walks you through why you should even care. Sure, many of us have features in mind and run straight for the finish line ... but this can really get painful on older systems. He even takes a moment to point out one of the biggest traps for developers new to OO. "The presence of classes does not guarantee object-oriented design, even in languages like Java, which forces you to do everything in a class."

The chapter hooks you right away with an example done procedurally and another in OO using appropriate abstract methods. The point is clear: with proper design, you can get away from the Giant If-Else Blocks of Doom and pave the way towards actually keeping up with your client's requests.

Finally, he defines and relates the concepts of Responsibility, Coupling, Cohesion and Orthogonality.

Another great nugget of advice has been planted in this chapter. According to Zandstra, the art of selecting and defining objects "...is far more than just finding the 'things'" in a system. "If you see a class as a noun, a subject for any number of verbs, then you may find it bloating as on going development and requirement changes call for it to do more and more things."

Never before have I seen a simple sentence more completely dispel the inappropriate "object oriented" lessons you may have learned in school. If anything; if you find that it hits too close to home, you will pay attention to what he is about to say!

After telling a story about classes gone badly: "How should we think about defining classes? The best approach is to think of a class as having a primary responsibility, and to make that responsibility as singular and focused as possible. Put the responsibility into words." He continues, referring to the writings of Peter Coad: "If your sentence gets too long, or mired in clauses, it is probably time to consider defining new classes along the lines of some of the responsibilities you have described."

Our tour continues through the basics of polymorphisms and encapsulation. After which, Matt provides us with "four signposts" to help identify problems that can creep into our designs:
  • Code Duplication
  • The Class that knew too much
  • The Jack of All Trades
  • Conditional Statements


For more detail on these tell-tale signs that are probably represented somewhere in your code, go buy the book.

Matt really surprised me in this chapter. After getting us up on all the OO syntax and concept basics, he pulls out the UML. What was so surprising is how easy and approachable he made this introduction. In just a few pages, you learn enough to diagram and interpret inheritance, associations, aggregation and composition, and actually know what all that means. As an added bonus, he even gives a useful introduction to sequence diagrams.

Now, a chapter on UML (or some diagramming set) is usually included in any pattern book. But, this is different from those others. Matt provides s a short, easy to understand introduction to just enough UML to communicate your concepts and processes. A very cool bonus indeed.

Part III - Patterns As Matt says in chapter 1, this book stands on the work of giants. He makes this obvious in parts III and IV. While some may say that he is just repeating what others are saying, I would disagree. The value he adds in basing the patterns in examples you can actually picture writing yourself is worth every delicious page.

After walking us though the why-and-how of how "design patterns" came to be, Matt again makes us actually care about spending the time to learn as many as possible and to use them when it is appropriate. Again, he does a great job of breaking these tough concepts into bite-sized chunks. Don't get me wrong, though; you'll be full after reading the chapters in this section.

I won't go into great detail, but I need to at least provide you with an idea of the patterns you will learn about in this section.

In chapter 8, Matt describes some of the most low-cost, high-return concepts around: composition, decoupling, "patternitis" and the golden rule of OO development -- "Code to an interface, not an implementation."

In chapter 9 he introduces us to some "creational" patterns: The singleton, abstract factory, factory method and prototype.

Chapter 10 focuses on "structural" patterns. The ones he focuses on are the composite, decorator and the facade.

You should note, most of this is PHP written as if we were developing a civ-style, Web-delivered game. This is much easier for "the rest of us" to digest and apply these examples than the GoF's examples of building a large-scale word processor. No disrespect to the bible that is the GoF, but if you have read about design patterns, and still need a little help applying the ideas to your day job, parts III and IV were written for you.

Chapter 11 introduces us to some great task and message management patterns: Interpreter, Visitor, Strategy, Command and Observer.

Finally, Chapter 12 drives us home and provides us with a great look at even more great patterns and explains how they fit into the three tiers of sustainable web development: presentation, business logic and data retrieval and storage.

Presentation
  • Registry
  • Front Controller
  • Application Controller
  • Templates and Template Views
  • Page Controller
Business Logic
  • Transaction Script
  • Domain Model
Data Access and Storage
  • Data Mapper
  • Identity Mapper
  • Unit of Work
  • Lazy Load


Part IV - Practice This is a very important section: like the intro, please don't be tempted to skip it. Matt reminds us while learning code and code design is great, it teaches you nothing about the day-to-day tasks associated with actually keeping the project alive and kicking.

In "Borrowing the Wheel," he shares with us a fantastic piece of advice; one that many PHP developers could stand to listen to:
When this temptation [to reinvent the wheel] comes over me I remind myself of projects past. Although the choice to build from scratch has never killed a project in my experience, I have seen it devour schedules and murder profit margins. There I sit with a manic gleam in my eye, hatching plots and spinning class diagrams, failing to notice as I obsess over the details of my component that the big picture now is a distant memory (p. 294).


Please, take another moment to read that again. If this sounds eerily familiar, please stop reading my review and head strait for your nearest book dealer.

In these chapters we naturally get the (hopefully) obvious hints: use version control, write tests, use PEAR, etc. But, where else will you find all this along with excellent references on actually using PHPUnit2, writing your own PEAR Packages for managing even your own code, actual phpdoc syntax and examples ... not just the act of documenting your code, but using the phpdoc command line tool. And with the section on using cvs, you will have absolutely no excuse but to save your life with some form of version control.

Matt even devotes an entire chapter to managing automated builds with Phing, the PHP equivalent of Apache's ant or C's make.

Most of this information is available in countless forums, articles and websites where you could learn about all of these topics for "free." Or, you could read this section in an afternoon or two and begin amazing your friends and better managing your code right away.

Part V - Conclusions Matt's summary and overview is a great recap of the journey he has put us on. But, on top of that, he outlines some of the essentials that he had to leave out. Here he at least mentions the importance of tools such as bugzilla, mail lists and a wiki for all that other documentation.

Looking at the Bibliography (and all the places he gives credit where credit is due) is like looking at the reading list of nearly every great programmer. You will find books such as: Core J2EE Patterns, Design Patterns (GoF), Extreme Programming Explained, A Pattern Language, Patterns of Enterprise Application Architecture, The Pragmatic Programmer, Refactoring and UML distilled. This is, of course, along with many on-line articles and websites.

Sure, you could spend years reading all of these sources (and some you still should) but unless you get paid to read, do yourself a favor and get some of the best of all of these texts, tailored to you in PHP and delivered in just over 400 pages. My General Impressions

As I mentioned earlier, one of my favorite features of this book is that the examples are "real." This is not some collection of abstract examples like building the next great competitor to Word -- these are website concepts we mere mortals can relate to, such as product catalogs, games, invoices, and the like. You know, the stuff we actually do for a living.

This book does not cover loops, conditionals, functions, operators or any of the non-OO basics of PHP, and believe me, I am grateful. If you would like an introduction to the language of PHP, simply check out php.net or one of the many great introductory books.

I would certainly recommend this book (as if there was any doubt) to any PHP developer. This is especially true for anyone interested in learning more about using objects and classes more appropriately than ever before.

I would also recommend this book to any Java, Ruby or Python developer out there who hears the letters PHP in a sentence and immediately responds with any number of colorful phrases. As we have all read the Pragmatic Programmer by now, we know we can learn something from reading up on any language, and PHP has never been better than it is today.

Finally, I would tell any web application developer who is looking for a quick way to absorb and comprehend the meat of some of the best development and design books ever written.

Read it for yourself and I think you will agree: the desk of nearly every PHP application developer will one day be holding a copy of this book.

Daniel Holmes maintains the PHP User Group in Kansas City since its inception in 2000. He is also the Systems Integration Manager at JCCC in Overland Park, KS. You can purchase PHP 5 Objects, Patterns and Practice from bn.com. Slashdot welcomes readers' book reviews -- to see your own review here, read the book review guidelines, then visit the submission page.

165 comments

  1. Nice by Programmerangel · · Score: 2, Funny

    Hmm...seems like an interesting book. Glad I learned the language last week. :)

  2. Seems a lot like... by op12 · · Score: 2, Informative

    the Spring Into PHP 5 book reviewed here earlier recently.

  3. OO Coding by Gunny101 · · Score: 0, Troll

    Want to know the best way to use objects in PHP?

    use Perl;

    *ducks*

    1. Re:OO Coding by dumeinst · · Score: 0, Troll

      Yeah, because perl has NATIVE objects

    2. Re:OO Coding by tthomas48 · · Score: 1

      Yeah, I have never met a perl zealot who though Perl's object oriented programing was better than any other language. That was always perl's biggest weakness. Now this book was entitled "How to process Strings in PHP", you might have a point.

    3. Re:OO Coding by WilliamSChips · · Score: 1
      Actually, for objects the best solution is
      use Python
      or possibly
      use Ruby
      --
      Please, for the good of Humanity, vote Obama.
    4. Re:OO Coding by pyrrhonist · · Score: 2, Funny
      Actually, for objects the best solution is
      use Python

      Okay...

      $ perl -e 'use Python'
      Can't locate Python.pm in @INC (@INC contains: /usr/lib/perl5/5.8/cygwin /usr/lib/perl5/5.8 /usr/lib/perl5/site_perl/5.8/cygwin /usr/lib/perl5/site_perl/5.8 /usr/lib/perl5/site_perl/5.8 /usr/lib/perl5/vendor_perl/5.8/cygwin /usr/lib/perl5/vendor_perl/5.8 /usr/lib/perl5/vendor_perl/5.8 .) at -e line 1

      Hmmm, not installed. Okay...

      $ perl -MCPAN -e shell

      cpan shell -- CPAN exploration and modules installation (v1.7601)
      ReadLine support enabled

      cpan> install Python
      CPAN: Storable loaded ok
      Going to read ~/.cpan/Metadata
      Database was generated on Fri, 20 Apr 2002 12:59:16 GMT
      Running install for module Python

      The module Python isn't available on CPAN.

      Damn.

      --
      Show me on the doll where his noodly appendage touched you.
  4. I like... by theotherlight · · Score: 2, Informative

    WROX's Professional PHP 5.

    This book sounds a bit more technical, but I've always loved WROX's style of writing.

    --
    The cat's in the bag and the bag's in the river.
  5. "the GoF"??? by Anonymous Coward · · Score: 4, Informative
    The Gang of Four is not a book. They are four guys who got together to write a book, and an excellent book at that: Design Patterns - Elements of Reusable Object-Oriented Software.

    In no particular order (other then that which appears on the front cover of Design Patterns), the Gang of Four is:
    • Erich Gamma
    • Richard Helm
    • Ralph Johnson
    • John Vlissides
    1. Re:"the GoF"??? by Anonymous Coward · · Score: 0

      Err, that would appear to be in alphabetical order by last name.

      I'd say that's a particular order, but I suppose I'm being mind-bendingly pedantic at this point :)

    2. Re:"the GoF"??? by adamfranco · · Score: 1

      an excellent book at that: Design Patterns - Elements of Reusable Object-Oriented Software.

      Having just taken Ralph Johnson's excellent Object Oriented Programming and Design class (CS598) at U. of Illinois, I'd just like to second the quality of the material in Design Patterns.

      While professor Johnson's class gave me a love for Smalltalk, I make heavy use of the patterns in my daily work developing PHP apps. Though PHP4 has a comparatively crappy object sytem, they patterns are still workable for the most part. I'll definately have to give this book a read as we transition to PHP5 as it sounds like it could be a nice refresher. As well, having examples in one's target language can be really useful.

      - Adam

      --
      "When ideology and theology couple, their offspring are not always bad but they are always blind." -- Bill Moyers
    3. Re:"the GoF"??? by Anonymous Coward · · Score: 0


      In no particular order (other then that which appears on the front cover of Design Patterns), the Gang of Four is:

              * Erich Gamma
              * Richard Helm
              * Ralph Johnson
              * John Vlissides



      Speaking of patterns, you listed them in alphabetical order by their last names.

    4. Re:"the GoF"??? by Frymaster · · Score: 2, Informative
      Though PHP4 has a comparatively crappy object sytem

      "comparitively crappy"? while i love php4 for its lightening-fast dev time and embarassingly forgiving syntax, it's oop implementation is far and away the worst i have ever seen.

      php started life as a procedural language, based on the ideology the that primary component of web development was the "page" or even the "session" and that adding another logical component system (the "object") was pointless. the oop capacity of php4 was little more than a gross retrofit. if the language can't enforce private methods, or grok object cloning vs referencing then it's really not useful for oop. in fact, i would go so far as to say php4 is not an oop language, but a procedural language with some oop capabilities.

      now, having said all that, it looks like the cats at zend have made a serious effort to build a meaningful oop language with php5 (i'm especially keen on exceptions) and i applaud them for taking the time to do it right. but i still stand by my initial statement: php4 isn't oop and, for the sake of the children, shouldn't be used that way.

    5. Re:"the GoF"??? by dhalgren · · Score: 1

      I agree with everything you've said (I've been using PHP since PHP/FI).

      But in the authors' defence (just for the reading public, not you--you don't seem to be slamming anyone), they agreed with you too. They made no bones about the fact that PHP 4 objects were essentially arrays which could contain functions, with some sugar like inheritance thrown on top for flavour.

      Some of us in the PHP community, on the other hand, might have gotten a tad overexcited. :)

      Torben

    6. Re:"the GoF"??? by dhalgren · · Score: 1

      Clarification:

      But in the authors' defence. . .

      I meant the authors of PHP 4.

      Torben

    7. Re:"the GoF"??? by OrangeGoo · · Score: 1

      In no particular order [...]

      Alphabetical. That's particular! :)

  6. Re:Code to try.... by thegamerformelyknown · · Score: 0

    You pass as a programmer?

    Wow, you HAVE to know what you missed there. No idea? ";". Fool :)

  7. Book Review or Book by guaigean · · Score: 2, Funny

    This book must be HUGE! Look how big just the review is!

    Joking aside, thanks for the tip. I'm also always looking for good resources, and am a huge fan of PHP for development (especially after having to recently fix a hellhole of an ASP site). This comes at a good time with the impending release of a stable PHP 5. Thanks again.

    --
    Microsoft Sucks, F/OSS Rocks. I get mod points now right?
    1. Re:Book Review or Book by WiFiBro · · Score: 3, Informative

      I agree, this is a bit too long for a review, it's almost a book, and where's the criticism?
      What do I do with a comment like "a very useful something-to-string-function in chapter X"

    2. Re:Book Review or Book by Anonymous Coward · · Score: 0

      I guess you never heard of asp.net, you stupid jackass oaf.

    3. Re:Book Review or Book by guaigean · · Score: 1

      And perhaps you've never had to fix someone else's mistakes, but it happens all the time, and sometimes you're stuck with what they did.

      --
      Microsoft Sucks, F/OSS Rocks. I get mod points now right?
    4. Re:Book Review or Book by aztracker1 · · Score: 1

      True enough, I'm not the GP here, and sorry to stray off topic, but the limitations of implimentation, and having to fix mistakes aren't necessarily a limitation of the environment... I've written plenty of OO code for Classic ASP... and right now, working mainly in ASP.Net.

      Right now, I'm stuck writing a bunch of logic in postback events that probably would be better client-side, but the rule where I am working at the moment, is it needs to be server-side, so the developers don't have to be fluent in JavaScript. It's completely ugly imho for usability, but the code is cleaner this way.

      To the same note, however I like that PHP has come to bring more OO features, especially in v5. I don't like that most of the internal class structure is a derived into a bunch of flat/global functions like SOMEDB_CREATECONNECTION returns dbconn, and then you have to call SOMEDB_GETRECORDSET(dbConn...) etc... it's all top-level, I wish it were more organized, similar to ASP.Net or JSP/Java for object structure and namespacing.

      I'm also hopefull that some more optimizations make it into the general PHP (for performance), without the need to pay Zend for it.

      --
      Michael J. Ryan - tracker1.info
    5. Re:Book Review or Book by Anonymous Coward · · Score: 0

      Ya, like the ASP technolgy made it a hellhole. The programmers made it a hell hole. VB Script has classes and can be used for abstration and encapsulation like all the rest and suffers from the same weakness that the rest of the weakly typed interpreted languauges suffer from. You pay for RAD. And of course PHP isn't a language that can be used anywhere else, so why not inveset in a book and in learning all kinds of high level programming techniques that can only be used in a web server tag language. Nothing worse than a one trick pony other than a one trick pony zealot. It looks like all of the mainframe coders switched to PHP. Was this article a paid advertisement. It is not news, not nerdy and does not matter. And yes, I am new here.

  8. Matt Zandstra has also written some articles... by tcopeland · · Score: 3, Informative

    ...for IBM developerWorks recently; here's his two part series on objects in PHP (part 1 and part 2).

    If you like to write tech articles, I recommend dW; they're a good crew. Some of their tutorials (like my GLib collections tutorial) require registration, but, hey.

    1. Re:Matt Zandstra has also written some articles... by singleantler · · Score: 1

      He's also just launched a new website - getInstance() and has lists of his articles on there, and a blog that looks like it'll be useful.

      --
      "What if they're using IE?" "I've dumbed Mozilla down to cope with it." - BOFH
  9. tell us by adnausium · · Score: 2, Funny

    why doesnt Daniel tell us how he really feels...

    --
    Don't ya hate it when the correct spelling of your favorite screen name is taken?
  10. I've said it before, I'll say it again, by Neil+Blender · · Score: 2, Funny

    and I'll be modded troll again.

    "PHP: Because 1,000,000 newbies can't be wrong."

      - Someone, not me.

    1. Re:I've said it before, I'll say it again, by hobbesx · · Score: 1

      I've said it before, I'll say it again,
      and I'll be modded troll again.


      For some reason, after reading this, my head echoed with a lilting:
      It codes the PHP with zen,
      Or else it gets the hose again!

      --
      This rating is Unfair ( ) ( ) Fair (*) Funny
      Sigh... If only. Modding would be so much more fun.
    2. Re:I've said it before, I'll say it again, by chris_mahan · · Score: 1

      Well, in that case:

      VB: Because 3,000,000 newbies can't be wrong in 1998.

      Oh wait.

      --

      "Piter, too, is dead."

    3. Re:I've said it before, I'll say it again, by jlarocco · · Score: 1

      Crap, I just ran out of mod points.

      That's the funniest thing I've heard all day.

    4. Re:I've said it before, I'll say it again, by $1uck · · Score: 1

      Once upon a time I wanted to learn php. I've done most of my programming in java and when it came time to do web apps I was told to you use JSP (and was thinking that would be best considering most of my experience was java). What does the acronymn PHP stand for ? (Pre Hypertext Processor?). Seems like its turning/turned into an entire language in its own right? If thats the case and it was built originally as being competition for asp/jsp/coldfusion etc I would think it would be kludgey as a full blown language. If it is a full blown language shouldn't and book on design patterns be appropriate?

    5. Re:I've said it before, I'll say it again, by Mad+Merlin · · Score: 1
      What does the acronymn PHP stand for ?

      PHP: Hypertext Preprocessor

    6. Re:I've said it before, I'll say it again, by dangermouse76 · · Score: 1

      again, my Amiga is better than your Atari..

    7. Re:I've said it before, I'll say it again, by rjshields · · Score: 1

      Your sign doesn't compile. Module "sarcasm" not found in library "wit".

      --
      In this world nothing is certain but death, taxes and flawed car analogies.
    8. Re:I've said it before, I'll say it again, by chris_mahan · · Score: 1

      Oh, the irony!

      You don't compile python code!

      Dude, if I was able to write a wit module and a sarcasm method in it... I'd write a bot to post to slashdot for me.

      --

      "Piter, too, is dead."

  11. "the GoF"???-Holub too. by Anonymous Coward · · Score: 0

    So how do you feel about "Holub on Patterns: Learning Design Patterns by Looking at code"?

    And what about all the other patterns?

  12. yep by Anonymous Coward · · Score: 0

    Glad we get our daily PHP book review here.

  13. true.dat.tar.gz by mnemonic_ · · Score: 3, Funny

    Hey, my job relies on my PHP knowledge, and even I agree with your statement. :)

  14. Re:1st Post by Anonymous Coward · · Score: 0

    PHP - Giving clueless webwhores the false impression they can "hack" or they understand basic principles of web-applications even before Rubile Off Roads.

  15. Web design and objects by acomj · · Score: 4, Interesting

    I find very little use for objects when I write Php.
    (except the very nice "smarty template" engine)

    I don't know why, because I program with objects all day at work, but for web design, they don't stick around between page loads (unless I'm missing something, Ajax et all). I use sessions all the time though. I find procedural stuff much snappier than recreating the class each time.

    1. Re:Web design and objects by tolan-b · · Score: 1

      It depends on the size of the project I find.

      All my PHP is completely OO.

      For larger projects it can make manageability a lot simpler, as you probably know from your work ;)

    2. Re:Web design and objects by Anonymous Coward · · Score: 0

      Smarty is a very good templating system.

      http://smarty.php.net/

    3. Re:Web design and objects by Doctor+O · · Score: 2, Informative

      Of course objects 'stick around between page loads' - just store them in your session and restore them as the first action on the loaded page. If you don't use sessions because you dislike cookies, just configure your PHP to use server-side sessions by default or cast the unholy INI set rune to override the unfavoured default.

      --
      Who is General Failure and why is he reading my hard disk?
    4. Re:Web design and objects by erikharrison · · Score: 1

      What you really need is a development framework to build your classes around that allows for persitence. The page based, highly transitive web model is broken, and Ajax works around that.

      If you put your objects in a framework which supports persistence, then old code works the same as it always has (with a potential performance boost) while allowing Ajax based applications to communicate with the object over the course of a session.

    5. Re:Web design and objects by dasil003 · · Score: 1

      What you really need is a development framework to build your classes around that allows for persitence. The page based, highly transitive web model is broken, and Ajax works around that.

      I agree, except you're mixing two unrelated ideas. AJAX is just a method for communicating with the server that doens't require the browser to reload the page. The server could be anything under the sun, with or without persistence.

      In response to the grandparent, the idea that you need persistence to make OOP worthwhile in PHP is a red herring. For small applications usually the pipe is the bottleneck, not the processor. If the application really does use that much processor, then using an imperative style is not likely to give you the performance you need anyway.

      No, the choice to use OOP or not should be based on software engineering principles, not perceived performance.

    6. Re:Web design and objects by pvera · · Score: 1

      I used to feel the same way until I got a second programmer on board and he was well-versed on PHP from the object-oriented side. Sure, it is a web-based application and there is no state, but the OO approach can save you a hell of a lot of trouble. Done right it saves you a lot in redundancies, plus as long as you don't mess with your interfaces you can work on the object itself without messing the pages that use it.

      Imagine an online community. Your user profile keeps 10-20 bits of information about each user (name, email, etc.). In the procedural world, you would need:

      1. User signup page
      2. User profile page, so users can edit their own profile.
      3. User management page, so site admins can moderate their membership.

      Each of these sections has its own sql commands, logic, etc. Of you have half a clue you will at least write some functions to centralize some of that code, but it is still procedural.

      Now, think OO. You can make a user class, and the class has methods to add/edit and list users. YOu still end up with the same pages:

      1. User signup page
      2. User profile page, so users can edit their own profile.
      3. User management page, so site admins can moderate their membership.

      The main difference is that these are much smaller, because there is no redundancy. The user signup page only has to grab the proper form fields and send them to the user object, which knows how to validate the user and add it. The user profile page works the same, it only has enough code to pull the user profile thru the object, and pulls the submitted form values and sends them back to the object. The admin pages work the same way, except that from the admin pages you have access to more methods within the object.

      And yes, smarty is teh bomb. The only thing we lack with smarty is exceptions. If you use smarty with php 5 you don't get template errors displayed on screen, instead you just get a blank screen, which is aggravating as hell. We are fed up enough with it that we are about to go ahead and hack smarty to use exceptions of it detects php 5, and then we'll send the code back to the smarty folks to see if they feel like adding the code to the main branch.

      --
      Pedro
      ----
      The Insomniac Coder
    7. Re:Web design and objects by Sepodati · · Score: 1

      Doing that still means the object is being serialized and saved in a file when the script ends, the object class is included and parsed again the next time the script runs and the object is unserialized and "recreated". That's not "sticking around between page loads"...

      ---John Holmes...

    8. Re:Web design and objects by rice_web · · Score: 2, Interesting

      But page loads suck. I hate to see pages crawl as they load; it's painful to watch. I know that this is a problem with the static web space in which we work, but it's a tremendous annoyance. I'm currently working on a development environment for PHP5 that will attempt to keep PHP applications "open", in so far as the developer sees the program. Imagine a case where the developer is coding an application that needs to attach an event to a button. For instance:

      <?php

      class ButtonApplication extends GFrame {

          public function __construct() {

              $Box = new GButton("Click me!"); // Construct similiar to JButton

              $Box->addActionListener($SomeAction);

              $this->add($Box);

              $this->setTitle("Button App");
              $this->setVisible(true);

          }

      }

      ?>

      Obviously, I'm trying to emulate Java's Swing -- I do need to brush up on my Swing :) -- but the idea is that any actions added to the $Box object could be coded as if the program were seamless. Behind the scenes will be an elaborate AJAX implementation.

      --
      The Political Programmer
    9. Re:Web design and objects by rjshields · · Score: 1

      .NET does this using a bit of javascript and some page state.

      --
      In this world nothing is certain but death, taxes and flawed car analogies.
    10. Re:Web design and objects by Anonymous Coward · · Score: 0

      You sound like a former manager. He didn't know why anyone would bother with functions let alone objects.

      Last I heard was that he was considering writing a book about programming.

    11. Re:Web design and objects by Tablizer · · Score: 1

      All my PHP is completely OO. For larger projects it can make manageability a lot simpler, as you probably know from your work

      Evidence? I have not seen any good evidence that this is the case. The few examples I have actually seen were comparing poor procedural/DB to decent OO. If they learned better pr/DB techniques, then the benefits they claim would just plain not be there.

    12. Re:Web design and objects by Anonymous Coward · · Score: 0

      As much as I'd like to have my world rocked by some hard evidence for OOP, I find it somewhat absurd that you're seeking it from web developers on slashdot.

    13. Re:Web design and objects by Tablizer · · Score: 1

      As much as I'd like to have my world rocked by some hard evidence for OOP, I find it somewhat absurd that you're seeking it from web developers on slashdot.

      I am not quite sure what your implications are here. Is it that web-apps can't use OO? Are "beneath" OO? That slashdot programmers are worse than average programmers? If somebody is using OO without knowing why it is allegedly better such that they cannot clearly demostrate or explain why, then they are probably not ready for OO.

  16. a short article from same author by Anonymous Coward · · Score: 2, Informative

    http://www.zend.com/php/design/patterns1.php?print =1

    You can get a taste of his writing skills which are pretty straight forward.

  17. sure, pedant by jbellis · · Score: 2, Informative

    but just about everyone refers to that book as, well, The Gang of Four.

    it's like the Dragon Book, but that's probably before your time.

    sorry to burst your bubble...

    1. Re:sure, pedant by Anonymous Coward · · Score: 0

      i learned a lot from that post. in my Software Engineering curriculum, I never studied compilers (went down to processor design, and up through software architecture, but never touched compilers).

      unfortunately, not enough people around me use Design Patterns (the book or the concept) enough for me to have ever heard it called by any other name.

      as to what i learned: pedant, The Dinosaur Book, my programming environment is too small.

      glad i'm started grad school soon.

    2. Re:sure, pedant by Anonymous Coward · · Score: 0

      by Dinosaur Book, I mean Dragon Book. (Dinosaur Book was my OpSys book).

    3. Re:sure, pedant by prockcore · · Score: 1


      it's like the Dragon Book, but that's probably before your time.


      I was really sad to see the new Compilers book no longer has a dragon on it.

      The dragon book is the only textbook I still have from college.

  18. Re:moD up by temojen · · Score: 0

    Did you actually click on the goatse link? Never click on the goatse (or tubgirl) link.

  19. the funny thing is... by Run4yourlives · · Score: 1

    There's a weird sort of backwards logic in your thinking there...

  20. Re:Code to try.... by Anonymous Coward · · Score: 0

    Yuck, short tags. Looks like you actually need to read the book :)

  21. PHP vs. RoR? by Colonel+Panic · · Score: 0

    At this point if I were just starting out in Web development, wouldn't I want to invest in learning Ruby on Rails instead of PHP?

    PHP had it's time. That time is now seems to be passing. For everything there is a time and a season: Now it seems to be the season of Rails.

    1. Re:PHP vs. RoR? by Philmeeh · · Score: 2, Informative

      You're forgetting that there are far more web hosts providing PHP than Ruby / Ruby On Rails. I am currently learning Ruby and Rails at the moment and did a quick trawl of web hosts forums and in every support forum that asked for possible support for Rails there was just the question "What is Rails?". PHP on the other hand is well known and has a lot of famous applications for it.

      If you have control over your own server environment it could well be worth swapping to Ruby & Rails.

    2. Re:PHP vs. RoR? by ciroknight · · Score: 2, Informative

      First of all, that third-to-last sentence was barely parsable, but I gotcha.

      Secondly, PHP and Perl are like the C and C++ of the web world. They're the oldest and most trustworthy platforms available now, and now since PHP has joined the ranks of full object orientation, it can be a serious competitor to VB/.Net.

      Too many websites, web applications, corporations, banks, etc. rely on PHP for it to just die. Ruby on Rails may be better, but it's very much a niche product, and it will take it a lot of time to gain momentum in the corporate world where competition in this particular market is FEARCE.

      Lastly, I think people will stick with PHP out of familiarity of the programming model. PHP4 felt just like scriptable C except the lack of types, which, frankly, pissed me off at the beginning, but later turned out to feel just right. Ruby on the other hand, reminds me a lot of Scheme/Lisp or Smalltalk, and is kinda foreign and alien to less experienced programmers (but no more foreign than Object C and it's Smalltalk origins, which I have to admit I have fallen in love with over the past year).

      --
      "Victory means exit strategy, and it's important for the President to explain to us what the exit strategy is." G.W.Bush
    3. Re:PHP vs. RoR? by Nasarius · · Score: 1
      You're forgetting that there are far more web hosts providing PHP than Ruby / Ruby On Rails.

      Which doesn't really matter if you're willing to shop around. I've found several inexpensive hosts that support Django, which hasn't even had a stable release yet. I'm sure you can find hosts supporting Rails.

      Sure enough, the Rails guys even have an official host. Reasonable prices.

      --
      LOAD "SIG",8,1
    4. Re:PHP vs. RoR? by Philmeeh · · Score: 1

      Yes but the majority of people won't shop around - they may already have a host that supports PHP. So they are more likely to say 'I may as well learn PHP'. It's that whole chicken and egg scenario.

    5. Re:PHP vs. RoR? by Mr.+Slippery · · Score: 5, Insightful
      At this point if I were just starting out in Web development, wouldn't I want to invest in learning Ruby on Rails instead of PHP?

      No, you wouldn't. PHP has a massive installation base, it's not going anywhere. RoR shows signs of being just the latest the flavor of the month, but even if it does persist it's a framework, not a language - works great if what you want to do fits into that frame, otherwise you spend your time trying to bend the bars of the cage.

      --
      Tom Swiss | the infamous tms | my blog
      You cannot wash away blood with blood
    6. Re:PHP vs. RoR? by WWWWolf · · Score: 3, Insightful

      Learn both. Or, I'd recommend learning stuff in this order: PHP (the basics of web programming or "what is this HTTP thing anyway"), PHP+Smarty (how to separate the Content from the Logic), and Rails (fimally, a sane programming language with a full-blown MVC separation). Or, alternatively, Perl, HTML::Mason, Rails.

      A beginner to web programming will probably look at Rails with the same way a beginning mountain climber will look at Kilimanjaro*. You can learn Rails first, but it's a whole new world to itself. You'll do much better if you learn "normal" CGI scripts first, be it in PHP or some other language.

      * And J2EE would be the Everest. But that's besides the point.

    7. Re:PHP vs. RoR? by ScottyH · · Score: 2

      I'm sorry, I know this is totally trolling, but FEARCE...bahahaha

    8. Re:PHP vs. RoR? by Anonymous Coward · · Score: 0

      PHP? Trustworth?! Hahahahaha...

      Banks with websites written in PHP? Hahahahaha!

      If Rails is niche, it's niche is the web. Pretty big niche.

      PHP is trash. Anyone with any experience and talent will tell you as much.

    9. Re:PHP vs. RoR? by Anonymous Coward · · Score: 0

      Yep, and if you want to get paid real money for doing web development, learn Java.

    10. Re:PHP vs. RoR? by Anonymous Coward · · Score: 2, Insightful

      PHP is trash. Anyone with any experience and talent will tell you as much.

      Well, they might say that Ruby is generally a much nicer language than PHP. However, what they all agree on is that programming language zealotry is the sign of a shallow programmer with an inferiority complex.

    11. Re:PHP vs. RoR? by Phrogz · · Score: 1
      "[Ruby on Rails] works great if what you want to do fits into that frame, otherwise you spend your time trying to bend the bars of the cage."
      Could you share some examples of cases where you've found the Rails framework (or the Ruby language) to be too restrictive? It sounds like you're speaking from experience, and I'd like to hear about your experiences.
    12. Re:PHP vs. RoR? by Anonymous Coward · · Score: 0

      Ruby on Rails is a framework (not a language, though you could say it defines a domain-specific language for web apps) that encourages "best practices" from the get-go. Unit testing, separation of concerns, keeping your code lean and mean. If that interests you, then check it out.

      PHP is just a language.. and a poorly-designed one at that.. example: no "finally" clause on exception handlers.. wha???? what's the point???

      If you just want to knock out a quick web page or two, PHP is fine, but if you want to "go higher", just start with Rails.

      As a newbie they'll seem pretty much the same at first, but once you start to outgrow PHP, Ruby will grow right along with you.

    13. Re:PHP vs. RoR? by matchboy · · Score: 1
      PHP has a massive installation base, it's not going anywhere.
      On that note. Let's all keep running Windows! As a person who has stopped working in PHP and has moved his business and new clients to Ruby on Rails... I can assure you, Rails is going to be huge in another year. :-) (at least it better be... ) ;-)
      --

      Robby Russell
      PLANET ARGON
      Robby on Rails
  22. For the economically conscious by worf_mo · · Score: 5, Informative

    For around 40 bucks

    This book is also available for $26.39 at amazon.

    1. Re:For the economically conscious by Geoffreyerffoeg · · Score: 2, Funny

      Oh wow. A Slashdot link to Amazon that doesn't contain a referral link!

      So there is hope left in mankind after all!

      (And thanks for stripping out the unnecessary session data, by the way.)

    2. Re:For the economically conscious by Unruly · · Score: 2

      it's even cheaper at bookpool.com

      http://www.bookpool.com/ss?qs=1590593804&x=65&y=11

    3. Re:For the economically conscious by damiena · · Score: 0

      Oh wow. A Slashdot link to Amazon that doesn't contain a referral link!
      So there is hope left in mankind after all!


      But what he didn't tell you was that he is the author.

  23. Re:Code to try.... by Anonymous Coward · · Score: 0

    <?

    echo "who cares?"

    ?>

    parse error on line 3

  24. MOD PARENT UP! by Anonymous Coward · · Score: 0

    Don't be mad, PHP fanboi!

  25. Patterns by spiffy_dude · · Score: 2, Informative

    I believe every single one of the patterns mentioned above share names with patterns out of the book by Martin Fowler (and company): Patterns of Enterprise Application Architecture. I'm not sure I would be as unqualifyingly kind as the author of this review about regurgitating them. They are great patterns, but is a PHP-ized version of these patterns worth the price when it's such a major part of the book?

  26. Re:Code to try.... by TheRaven64 · · Score: 4, Insightful

    Troll? Maybe. I am getting slightly tired of all of the books around with titles like `Good programming practice in buzzword-language-of-the-week'. Good programming practice is good programming practice. It doesn't matter if it's in C, Smalltalk, LISP, or any other Turing-complete language - the concepts are the same. The only difference is syntax - some languages (and frameworks) support good practice better than others. Learning good practice in a way that is tied closely to a specific language will not make you a good programmer.

    --
    I am TheRaven on Soylent News
  27. Re:Code to try.... by merreborn · · Score: 1

    Actually, a closing ?> tag also serves as a ; That code is perfectly legal, albeit sloppy

  28. EXACTLY. by Jeffus · · Score: 1

    My thoughts exactly. Learn how to really program well in a real language and never have to buy something like this again.

  29. PHP? by killermookie · · Score: 1

    What is this PHP you are referring to?

    </sarcasm>

    1. Re:PHP? by Anonymous Coward · · Score: 0

      It was what old people in korea used before the all encompassing, world changing Ruby on Rails came through and made anyone who thinks of using php a complete moron. Three cheers for small unknown programming languages that have a following similar to a religon that says all are religons suck and you are going to hell if you don't join this one.

    2. Re:PHP? by TarryTops · · Score: 1

      Well, It's actuially called PHP = People Hate PHP...heh heh

      --
      Java Oracle Linux Enthusiast
    3. Re:PHP? by Anonymous Coward · · Score: 0

      ..heh heh

      You fucking moron.

  30. Re:Doesn't RoR make PHP obsolete? by Anonymous Coward · · Score: 0
    With the advent of Esperanto isn't it over for English?

    Rails is only good for generating CRUD screens.

  31. Head First Design Patterns by Philmeeh · · Score: 1

    I've flicked through this book at work - overall it is a great book but it isn't the best book to learn Design Patterns with. I would suggest "Head First Design Patterns" by Freeman and Freeman. The examples are in Java but it should be fairly easy to port the patterns over to PHP (plus it will build up your experience with PHP5 Object-Orientated programming). You can find out more information about the Head First Series at Wickedly Smart.com

  32. Re:Code to try.... by Gobelet · · Score: 1

    Well that's not what says my webserver. Since there's only one command to be interpreted you do not need to say to PHP "here's the end of this instruction, everything after that is unrelated." Therefore, you don't need it in that case.

  33. Or learn a real programming language.. by delus10n0 · · Score: 0, Troll

    Like .NET, preferrably C#. You know, something you'll use in the real world and get hired for. It's free, and it's much better than PHP.

    --
    Not All Who Wander Are Lost
    1. Re:Or learn a real programming language.. by ScottyH · · Score: 1

      Well, it's definately a nicer language to write (and VS.NET just makes it so FUN to code)...but to go as far as saying it's better? It's just another tool.

    2. Re:Or learn a real programming language.. by ThaFooz · · Score: 1

      Well the code the I deal with at work is about 50% Java and 50% PHP. They were chosen over C# and ASP.NET for platform independence; we don't consider vendor lock-in and a costly OS 'free'. .NET is great for quickly developing robust apps for windows users... but what else? Any one of these languages is just another tool, the reason there are so many is precicely because there is no be-all-end-all solution.

    3. Re:Or learn a real programming language.. by TheInternet · · Score: 1

      Like .NET, preferrably C#. You know, something you'll use in the real world and get hired for. It's free, and it's much better than PHP.

      Regardless of which is "better," there's really no shortage of PHP work. It's probably the most widely-used scripting language on the web.

            - Scott

      --
      Scott Stevenson
      Tree House Ideas
    4. Re:Or learn a real programming language.. by The_DOD_player · · Score: 1

      strange... I get payed good money writing PHP-code all day.

    5. Re:Or learn a real programming language.. by jinushaun · · Score: 1

      This is very true in my area (Seattle). I was quite distressed after all the years of PHP I've done to see how little demand there was for PHP programmers. Java and .NET are king.

    6. Re:Or learn a real programming language.. by delus10n0 · · Score: 1

      Define "good money". 20k a year doesn't count.

      --
      Not All Who Wander Are Lost
    7. Re:Or learn a real programming language.. by delus10n0 · · Score: 1

      Yeah, and I like how I get modded down for speaking truth.

      Like I said, the real businesses/large corporations are _not_ using PHP for applications, and will probably not hire you for PHP skills.

      --
      Not All Who Wander Are Lost
    8. Re:Or learn a real programming language.. by The_DOD_player · · Score: 1

      Good money... well. I finished CS-school in 2002. I get what amounts to 58k/year in US currency.

      Thats for a 37 hour/week, part PHP-programmer, part Unix-admin (Gentoo and Debian) job.

      Thats good money for me... :)

  34. Re:Code to try.... by Anonymous Coward · · Score: 0

    Any good books you'd suggest for the task?

  35. Speaking of PHP User Groups by djcatnip · · Score: 1

    If you live in the san jose area, and you'd like to meet about PHP/Mysql, check out my post, and left a message. http://www.somejunkwelike.com/wordpress/2005/03/07 /south-bay-php-user-group-meeting/

    --
    I make these: http://beatseqr.com
  36. Re:Code to try.... by Anonymous Coward · · Score: 0
    Have you ever coded in PHP? or coded for the web. It is completely different from other programming I have done.


    Programming for the web is always a mix of multiple languages.


    There are no compilers and debugging in a browser takes forever. Oh and all the compilers (read browsers) give completely different results because they are buggy. When was the last time you used a C compiler with bugs that caused more than a performance hit?


    Give me C/C++ and a make file and I will produce nice clean code.
    Doing the same in the combination of PHP/HTML/JS that is the web is much much harder.

  37. Re:Code to try.... by thegamerformelyknown · · Score: 0

    Hmm, really?

    Well, slap me silly, I should know that :P

  38. Spell-czeck by musselm · · Score: 1

    It's not that hard, man..

  39. what PHP stands for... by Xtifr · · Score: 2, Funny

    > What does the acronymn PHP stand for ?

    I've been told that it stands for "Poorly Hacked Perl", but somehow I doubt that, no matter how appropriate it may seem. :)

    1. Re:what PHP stands for... by Anonymous Coward · · Score: 0

      Nope, it's actually "Perl for Hopeless Programmers".

    2. Re:what PHP stands for... by b10m · · Score: 1

      I always thought it stood for "People Hate PHP" ...

  40. PHP stood for Personal Home Pages by freezin+fat+guy · · Score: 3, Informative

    PHP's author never envisioned it becoming a mainstream language. It tied into Perl to do its processing and had some massive security holes. There is a surprising amount of hate filled FUD surrounding the language these days (???) but an objective look at the modern PHP language/platform will show it suitable for a broad range of web applications. Perfect? Hardly. But wonderfully pragmatic for most everyday tasks.

    Good design and OO will only help those who have more serious needs. In that vein I would love to see future versions focus on scalability (yes, I do realize that Yahoo runs on it but not without some serious configuration) and perhaps persistance?

    Fortunately there's lots of great development tools and when PHP fits, I say use it.

  41. Get the syntax right, at least by Yolegoman · · Score: 4, Funny

    First off,
    Correct code:
    <?PHP
    echo 'Who cares?';
    ?>

    1. Re:Get the syntax right, at least by iamdrscience · · Score: 1

      Yes, "
      As for the semi-colon, it's not necessary because in PHP, like many languages, it's used as a statement seperator, not a statement terminator. This means that the last statement in a script (or code block) does not need a semi-colon after it. That script will run just fine.

      I WIN! I AM MORE PEDANTIC! YAY!!

    2. Re:Get the syntax right, at least by Anonymous Coward · · Score: 0

      "you may want to change your double quotes to single quotes, as it will save the parser a bit of time" -> Benchmarks show that the effect is minimal and almost inmeasurable.

    3. Re:Get the syntax right, at least by fbjon · · Score: 1
      No, not quite.

      Ultimate pedantry requires efficiency. Two newlines can be removed, which yields a total reduction of 3-5 bytes depending on the server OS, reducing disk access times and wear in the (very) long run:

      <?PHP echo 'Who cares?'?>

      I win.

      --
      True confidence comes not from realising you are as good as your peers, but that your peers are as bad as you are.
    4. Re:Get the syntax right, at least by russx2 · · Score: 1
      Getting even more pedantic here but, assuming the server is OK with
      <? ?>
      style syntax (which I believe is on by default now), this wins:
      <?='Who cares?'?>
      Another 3 characters saved ;-)
  42. Java? by mfh · · Score: 1

    I'm not going to mince words. I think that if you have a book on Java, it really only applies to Java. Anyone can claim a book will apply to other languages, but some differences could cause confusion and hours of lost productivity. I might read the book you suggested but I wanted to make it clear that I would be only reading it in terms of Java and not PHP. Mixing languages is what causes so many compsci students to skip class and play Quake.

    --
    The dangers of knowledge trigger emotional distress in human beings.
    1. Re:Java? by The+Clockwork+Troll · · Score: 2, Funny

      So clearly The Art of Computer Programming is only valuable if you plan to write code targeting the popular MMIX platform.

      --

      There are no karma whores, only moderation johns
    2. Re:Java? by rburt3 · · Score: 1

      Not to be inflamitory, but catering to this attitude is why many US institutions are cranking out mediocre programmers with astonishing speed. Unless you're in a good, traditional CS program, too little time is spent on the theory of programming language and too much on teaching tools. In a practical sense, this is not a bad thing if your goal is to simply enter the workforce and crank out accounting programs in VB. It is deadly, however, if your goal is to advance your skills and participate in more complex and exciting projects.

  43. neg by veggie_burger · · Score: 1

    ativity in here? what gives? - if you dont like the review, php or life in general please give some intelligent reason as to why.

    I thought there was a higher level of respect at slashdot... guess i am showing my n00b.

  44. Upgrade your programming style by MourningBlade · · Score: 2, Interesting

    If you'd really like to upgrade your programming style, why try a real book?

    I see so much stuff about writing better OO code, better Java, better PHP...hardly much at all about changing the way you think about programming. I know it's written about Lisp, but it's a book about high-end coding - about what being a master at code is all about.

    Free download here.

    1. Re:Upgrade your programming style by Anonymous Coward · · Score: 0

      On Lisp is impenetrable for novices. SICP would be better suited.

    2. Re:Upgrade your programming style by tjr · · Score: 2, Interesting

      Lisp is a most excellent language, and On Lisp is a very good book.

      It may be an uphill battle to see Lisp become popular, but even if you doubt that you would be able to use Lisp in any real projects, I would still highly recommend spending some serious time learning Lisp.

      Perhaps devote time to studying Lisp over the course of a year or two. Why so long? Because Lisp is so different. Unless you already know functional programming, you probably won't digest it all in a week or two.

      Take a look at Paul Graham's essays on Lisp, to start with, and to whet your appetite, and also his books.

      In addition to Paul's books, consider "The Little Schemer" or "How to Design Programs", which use the Scheme dialect of Lisp. "Essentials of Programming Languages" uses Scheme to implement interpreters, and you can learn a lot about Lisp through this book as well.

      As the previous poster implied, learning how to program in Lisp changes the way you think about programming, and this change affects how you program in _any_ language, not just in Lisp.

      That said, PHP is still a good thing. It's great for doing web applications. I just wrote my own custom web log software a few weeks ago, using PHP, and had a grand time. It was a good tool for the job.

    3. Re:Upgrade your programming style by Anonymous Coward · · Score: 0
  45. Wired=PHP 5 by MichaelPenne · · Score: 1

    Tired=RoR
    Expired=PHP 4

    Get with the program already:-)

  46. Re:Code to try.... by emmetropia · · Score: 1

    Oh lord, i'm feeding the troll...

    Oh and all the compilers (read browsers) give completely different results because they are buggy.

    Your browser is most definitely not comparable to a compiler, especially in the case of PHP. PHP is interpreted on the server side, and you never see what was scripted. I "compiles" what could best be compared to a bytecode, that your browser executes, in a semi-standard way.

    It's like a java app, in a way. What gets delivered to the user is the same (the bytecode), but theres slightly different widgets (rendering quirks). (Just to put this out there, I don't know if that's actually the case, I just assumed it would be)

    By the way, anyone who's a good "programmer" would not mix html and javascript up in their PHP. Always separate logic from presentation.

  47. The "cost" of PHP5 by kstumpf · · Score: 1

    Beware that if you plan to run PHP5 on a large scale, you really need to buy Zend Platform ($1500 per multi-cpu server). Running a large application without an opcode cache requires ALOT more memory, and the free opcode caches (apc and eaccelerator) do not optimize PHP5's new object syntax well, if at all. Do some simple testing on such an app with memory_get_usage() or a debugger and you will quickly see what I mean.

    I was looking at PHP5 as a platform for a rails-like MVC framework, but it would cost over $15,000 in licensing for it to run on our cluster on the scale we need. The free accelerators are finicky and questionably stable. I do not trust them yet, though I'm sure they'll improve. We decided to go with mod_perl and Catalyst with custom model classes as a framework.

    Frankly, Zend makes me nervous (it took two weeks to get a response to a sales inquiry). If I were to spend this kind of money it would probably be on .NET, which I think is a nicer framework. Too bad I don't like windows as a server.

    At any rate, be careful.

    1. Re:The "cost" of PHP5 by Anonymous Coward · · Score: 0

      I thought that the Zend Optimizer was a free download?

    2. Re:The "cost" of PHP5 by stunami · · Score: 0

      Yeah it is " Run encoded files and enhance the performance of your PHP scripts - FREE" url:http://www.zend.com/store/products/zend-optimi zer.php

  48. I've been considering the same thing... by TheInternet · · Score: 2, Informative

    At this point if I were just starting out in Web development, wouldn't I want to invest in learning Ruby on Rails instead of PHP?

    I've been thinking about this too, but PHP seems to win hands down in the deployment category. It looks like a lot of Rails apps use lighttpd, but a lot of people are very happy with Apache.

    You can use mod_ruby, but this gets tricky with multiple applications on the same server instance. The "preferred" deployment method seems to be FastCGI, but this seems like a strange option to me. I worked with FastCGI at a 4 million+ member site, and we were happy when we were able to leave FastCGI behind. It ate up gobs of resources. Maybe things have changed since then?

    Another area that's a bit more grey is syntax. Ruby has all sorts of special syntax, some of which is quite clever, but one person's "clever" is another's person "bizarre." Probably not quite as vexing as Perl, though. For better or worse, PHP doesn't have much special syntax. Personally, I think this is good.

    Finally, I've found PHP to be unbelievably fast. There's been dozens of instances where I was sure I'd have to spend time optimizing an application, but was proven wrong. Your mileage may vary, of course.

    There's a lot that Rails does right, but I'm not yet convinced it's the only reasonable optional for medium-sized apps. Of course, this gets a bit muddle because we're really comparing a framework to a language.

    --
    Scott Stevenson
    Tree House Ideas
    1. Re:I've been considering the same thing... by matchboy · · Score: 1
      There's a lot that Rails does right, but I'm not yet convinced it's the only reasonable optional for medium-sized apps. Of course, this gets a bit muddle because we're really comparing a framework to a language.


      Okay, let's compare the object-oriented power of Ruby to the nice oo addons that PHP5 has given us.

      Ruby > PHP5 (in terms of OO)

      Therefore, it is likely that any framework which fully utilizes that power (Rails) is a more powerful object-oriented framework. This is just a generalization... but I agree. Let's stop comparing PHP to Rails.

      Ruby vs PHP. Aside from a large userbase and a bunch of legacy php applications, what does PHP have over Ruby?
      --

      Robby Russell
      PLANET ARGON
      Robby on Rails
    2. Re:I've been considering the same thing... by TheInternet · · Score: 1

      Ruby vs PHP. Aside from a large userbase and a bunch of legacy php applications, what does PHP have over Ruby?

      Going back to my first post, I think the biggest thing is that PHP has deployment absolutely nailed. PHP is easier to deploy on your own server, and practically every hosting company in creation supports it.

      I have reservations about FastCGI and mod_ruby apparently isn't all that safe (if I want to use Rails). If I need to stick with Apache, what do I do?

      In terms of the language syntax (perhaps this is what you actually meant), I agree there's a lot to like about Ruby, and it's clearly built as OO from the start. That said, I've also found a lot of things that fly in the face of "least surprise".

      I see all of this through the eyes of a Cocoa programmer. In the Cocoa world, ambiguity is avoided at all costs. I see more room for ambiguity in Ruby than PHP, but I'm not at all a Ruby expert, either. I'm going to continue playing with Ruby on my own time, but I have no plans to deploy it right now.

      --
      Scott Stevenson
      Tree House Ideas
  49. Languages spoken h3r3 by threedognit3 · · Score: 0, Offtopic

    All you programming geek-a-stupids have one thing in common... y0u all masterbate, using your mother's underware, at different frequencies.

    1. Re:Languages spoken h3r3 by Anonymous Coward · · Score: 0

      This is probably the most accurate and insightful post on this thread!

      Another wunnerfull day in slashpot land :(*

  50. suggestions? by bucky0 · · Score: 1

    what'd i'd really like is a perl book on the same topic...does anyone have suggestions?

    --

    -Bucky
  51. real code by oglueck · · Score: 0, Flamebait

    If you really cared about OO design and good code you would not be coding in PHP but Java, .Net or C++. PHP is just not suited for real-world web applications. Rather read The Pragmatic Programmer than a book about a specific language.

    1. Re:real code by Anonymous Coward · · Score: 0

      >>PHP is just not suited for real-world web applications.

      Fucking bullshit!

      Have you any idea how many 'real world' applications there are in PHP?

      OO design is only important were it adds value - it is not some panecea.

      Sounds like a Pragmatic Programmer is the last thing you are.

    2. Re:real code by oglueck · · Score: 1

      Just one simple example. Every medium sized webapp has a rather large configuration vector. Configuration is today often done in XML. As PHP does not have application state it is not possible to perform an application startup and read the config once and then store it for later use. With every request you have to configure your whole application again. This can be a bad performance killer.

  52. Re:Code to try.... by thallgren · · Score: 1

    The patterns are not the same for all languages. If you program assembly language you would use patterns for things like sub-routine creating/calling/exiting.

    Likewise in C, which has sub-routines built-in, you would probably have patterns related to creating an OO flavour. Instance pattern, inheritance pattern, method call pattern etc.

    So if you think that these books are all the same, perhaps you have grown out of the level of computing C/Java/C#/C++/Smalltalk offers and are ready to take the next step. Perhaps CLOS in Common Lisp or Prolog can be a good start?

  53. Re:Code to try.... by dangermouse76 · · Score: 1

    did they say they was mixing logic and presentation? Nearly all websites these days require a combination of a server side language, browser side and obviously html. Other than that you pretty much agreed with the post.

  54. Pretty Homo Programming by Anonymous Coward · · Score: 0

    Pretty Homo Programming.

  55. Zend Optimizer is not a cache by mgkimsal2 · · Score: 2, Interesting

    The Zend Optimizer (ZO) is not a bytecode/opcode cache. The ZO injects itself into the processing of scripts and will allow the Zend Engine to decode Zend encoded files. It will also try to optimize the compiled bytecode. It's this second step where the performance gains can be seen, in some cases.

    However, without a code cache of some sort, the optimization steps will be run on every request. The ZO will cache the results of the optimizations, which is the optimal way to go about it.

    Example:

    You have a script which takes 50ms to execute. ZO can take 15ms to 'optimize' it down to 40ms of execution time. If the optimized code was cached, then every further execution of the script would take 40ms - a 20% speed up. But you're only getting that 20% speedup at a rather extensive processor hit. It's not worth it, so the ZO can actually slow down some code (especially if you're already gone through an optimized your code by hand). The ZO also doesn't even attempt certain types of internal optimizations unless the Zend Cache is present because it knows some of these analyze/optimize cost/benefit ratios just make *no sense* ever.

    The ZO is a mixed bag, and I've rarely seen it do anything noticeable in the past few years. It consider it more just a way for them to seed the market to make it more attractive to use the Zend Encoder. Not that that's a bad thing - I'm not criticizing them for it. It's just that the real performance boosts come from opcode caches. Any code that gets a significant boost from ZO alone was probably written very poorly to start with and could be mostly fixed by hand in the PHP source directly without requiring an external helper app like ZO.

  56. Re:Code to try.... by emmetropia · · Score: 1

    I was implying that the server-side portion of things shouldn't be mixed with the client side of things. That basically means, not mixing your PHP throughout your html/js. I fully agree that folks will work with all three, but they shoudl never work with more than one at a time.

  57. Re:Code to try.... by dangermouse76 · · Score: 1

    Are we talking server/client or logic/presentation?

    As long as logic is clearly seperated from the presentation i see no problems in having server side code mixed in the html/js as long as it is for presentation.

    Maybe i am misinterpreting what you are saying?

  58. I've said it before too by Anonymous Coward · · Score: 0

    You can't post an article even vaguely about PHP without /. idiots replying with "OMGWTF PHP, l4m3!!111"

    you got us, we're pwned, good work. the sad thing is, you WEREN'T modded troll. And you had 3x the "funny" that you did "flamebait" "redundant".

  59. PHP5 was a huge disappointment by matchboy · · Score: 0, Troll

    The solution?

    # assuming Ruby is installed..

    wget http://rubyforge.org/frs/download.php/5207/rubygem s-0.8.11.tgz
    tar zxvf rubygems-0.8.11.tgz
    cd rubygems-0.8.11
    sudo ruby1.8 setup.rb
    sudo gem install rubygems-update
    sudo gem install rails

    cd ~
    rails goodbyephp5
    cd goodbyephp5

    script/server &

    lynx http://localhost:3000/
    # woo!

    --

    Robby Russell
    PLANET ARGON
    Robby on Rails
  60. Started in PHP, switched to Ruby/RoR- here's why by 5n3ak3rp1mp · · Score: 2, Insightful

    I was implementing some coding algorithm that required using an unsigned int. Believe it or not there is no way to create or use an unsigned int in PHP (I even tried "faking it" by twiddling the most-significant bit of a signed int by ORing with a known value, but I just couldn't fool it)... but Ruby has that capability. So I successfully implemented the algorithm in Ruby, really started to like the features of the language a lot ("everything is an object" is actually pretty nice; data that comes from the outside is automatically flagged as "tainted"; blocks; some neat features borrowed from Perl and Smalltalk; mixins vs. multiple inheritance etc.) and next thing I knew I didn't want to write any more PHP.

    The "tainting" concept in particular was pretty revealing. Ruby will not only "taint" any data that comes from the outside (web forms, etc.) but also any objects that touch that data. I was kicking myself trying to figure out why I kept getting security errors, I was about to delete /usr/bin/ruby when googling finally revealed the answer- Ruby was trying to protect me from unvalidated input! All I had to do was object.untaint and it would trust me. Oooooooh, I said, that is cool! (even though it bit me in the arse at first)

    There are many aspects of the language like that. And there are also many aspects of RoR like that.

    I know it's just M.H.O. tho, but if I were to be a betting man, I would put my money on Ruby (carried by Rails) as the next up-and-coming enabling scripting technology. I haven't built anything large-scale with it yet, but I have found it very enjoyable to build the things I have so far.

    The lack of a huge installed base is just a temporary setback. If this is one's prime motivation, then everyone should just stick to Microsoft ASP and forget about any alternatives.

  61. Re:Doesn't RoR make PHP obsolete? by matchboy · · Score: 1
    Rails is only good for generating CRUD screens.


    Wow, you really haven't played with it much. Have you?
    --

    Robby Russell
    PLANET ARGON
    Robby on Rails
  62. Re:Doesn't RoR make PHP obsolete? by Anonymous Coward · · Score: 0

    Finally, somebody who realizes that Rails is good for the low end. It competes with PHP, not J2EE and .NET.

  63. Zealot alert, sound the alarm! by Anonymous Coward · · Score: 0

    I've used Rails for a year and used Ruby to some extent in over 50 large-scale commercial projects. I don't "play" with software.

  64. Re:Code to try.... by Anonymous Coward · · Score: 0

    I got this book about 6 months ago, and found it VERY helpful. At that time, I knew PHP and knew some simple OOP, but didn't know much about patterns or class design. Seems to me there are probably LOTS of PHP coders out there in a similar position, who are just looking to improve their existing practises and apps, and don't necessarily have time to learn C++ or Java just so they can read the Gang of Four book (or others of that sort) with much hope of getting anything really useful from it.

    After reading Zandstra's book, not only could I use PHP classes and objects much more effectively, I was also able to give *Design Patterns* another try and actually make some sense of it.

  65. My implication by Anonymous Coward · · Score: 0

    Your average slashdot poster is more likely to be satisfied with OOP brochure-talk than, say, the more academic types over at LtU.

    1. Re:My implication by Tablizer · · Score: 1

      Thanks for the link. My reply there basically said that paradigms may be personal, and what rocks his mental world may not rock others'. Just don't force feed your preference onto others. WRT "OO better models physical world", even many OO fans don't agree with that statement. How does one measure how well something fits the real world anyhow? And what about domains that deal with intellectual/virtual concepts and property such as tax law?

    2. Re:My implication by Anonymous Coward · · Score: 0

      Couldn't agree more.