Slashdot Mirror


PHP In Action: Objects, Design, Agility

Michael J. Ross writes "Despite being perhaps the most popular Web language in use, PHP has for much of its history been criticized for not offering the full capabilities of object-oriented programming (OOP). But with the release of version 5, PHP introduced a robust object model, and made it easier for its proponents to create well-architected Web sites and applications. In turn, the new OOP capabilities have facilitated additional best practices, such as design patterns, test-driven development, continual refactoring, and HTML templates. These topics and more are explored in the book PHP in Action: Objects, Design, Agility." PHP in Action: Objects, Design, Agility author Dagfinn Reiersol, Marcus Baker, Chris Shiflett pages 552 publisher Manning Publications rating 8/10 reviewer Michael J. Ross ISBN 1932394753 summary A pragmatic guide to object-oriented PHP development. Authored by Dagfinn Reiersøl, with Marcus Baker and Chris Shiflett, the book was published on 3 July 2007 by Manning Publications, under the ISBNs 1932394753 and 978-1932394757. Its subtitle accurately reflects the major themes of the work: creating PHP applications built upon objects, utilizing Web-oriented design patterns, and incorporating agile programming techniques such as refactoring and test-driven development. Also covered are methods for effective form handling, database extraction, date and time representation, and more.

As a result of trying to adequately cover such a large number of major topics in a single book, the amount of material is considerable, and the book is certainly longer than the typical Web programming book in general, and PHP book in particular. Spanning 552 pages, the material is organized into 21 chapters, grouped into four parts: In Part 1 ("Tools and concepts"), the authors discuss PHP 5, its strengths and weaknesses, and how well it can be used with advanced programming principles; an overview of objects, exception handling, and references; visibility, abstract classes, and interfaces; effective use of classes and object-oriented design; inheritance, composition, and more on interfaces; advanced object-oriented principles; six design patterns that are especially appropriate for Web-based systems (Strategy, Adapter, Decorator, Null Object, Iterator, and Composite); and lastly, date and time handling using objects.

For developers well-versed in OOP, Part 1 may be more of a review, while Part 2 ("Testing and refactoring") could be the most valuable portion of the book. In the four chapters, the authors dig into the details of test-driven programming, refactoring, and Web testing. These chapters and all that follow take a very pragmatic approach to conveying ideas, which is consistent with the theme of Manning's "In Action" series, based upon the idea that programmers tend to learn best by reading sample code instead of generic discussion. For instance, test-driven development (TDD) is demonstrated by showing how to implement database transactions, a contact manager, and e-mail functionality. Mock objects and top-down testing are illustrated through the creation of an e-mail class, and further extended with a discussion of faking the mail server. Given that testing is the primary theme of the entire part, one might expect a more lengthy discussion of TDD, but Reiersøl correctly notes that this particular book is not trying to replace the many manuscripts and articles already published on agile development; also, the database examples adequately demonstrate the general principles discussed prior. The chapter on refactoring is well worth reading, and touches upon the controversial topic of how much one's PHP code should be separated from the HTML code — a topic later revisited in the chapter on templates. Also explored is a topic critical to maintenance programmers — refactoring versus rewriting. Two different testing frameworks are discussed, PHPUnit and SimpleTest; the latter is used throughout the book. The final chapter in this part explains how to test Web pages programmatically, by faking interaction, and other techniques. The chapter ends with a section providing steps on how to deal with "the horror of legacy code," when the unfortunate programmer has inherited a nightmare of a live Web site.

The third part of the book, "Building the web interface," begins with an examination of templates, the arguments for and against them, and three of the most commonly used template engines: Smarty, PHPTAL, and XSLT. One of the previously discussed design patterns, Composite, is utilized for combining templates to create complex Web pages. The chapter on user interaction makes use of the Model-View-Controller architecture, with the subsequent chapter delving deeper into the topic of controllers for Web pages. The next two chapters cover an area of site development that is a frequent cause of uncertainty, "bandage coding," and security risks: user forms and input validation. The book's coverage of the PEAR package HTML_QuickForm, alone makes it worth reading. Part 3 concludes with a chapter on abstracting database resources through objects and the Singleton pattern.

The fourth and last part of the book ("Databases and infrastructure") is relatively brief, comprising two chapters on marrying SQL with object orientation. The authors present a number of techniques for shoehorning SQL transactions into object-based code, including encapsulating queries inside of methods, building SQL statements dynamically, substituting SQL elements such as column and table names, using SQL aliases, and using SqlGenerator.

It is clear that the lead author, Dagfinn Reiersøl, has put a tremendous amount of time (three years, as noted in the preface) and effort into creating this work. The discussions are wide-ranging and in-depth, and there is just enough sample code to illustrate the ideas being discussed and also break up the visual monotony. The illustrations are limited in number, and consist mostly of class diagrams and UML sequence diagrams. Overall, the treatment of each topic clearly reveals that he has considerable experience with them, and has given thought to the pros and cons of some possible approaches, though not all of them.

However, there are still some weaknesses in the book. For example, in all of the material discussing how to separate the SQL code from the PHP code, I found no mention of stored procedures, such as those made possible in MySQL. All of the sample code appeared to be solid, though there was no clear reason for the inconsistent use of print() versus echo() is different code samples. All of the chapter summaries could be excised without any loss of value, and many of the chapter introductions could be eliminated as well or condensed.

On a more mechanical level, the book had many minor weaknesses: It was not encouraging to see the first erratum even before reaching page 1: "raising own level" on page xix, in the second paragraph. Readers may initially be confused by such attributions as "Uncle Bob [Uncle Bob]" (on page 77). In a future edition, it should be explained that names in square brackets are biographical references listed in the Resources section, which follows Appendix B. In the first sentence in Chapter 12, the reference to "Jackass" will probably be confusing to many readers — particularly non-Americans — and is not in the best of taste. In the text and the table of contents, the chapter and part titles are written in sentence case, instead of title case, for no obvious reason. It is not clear whether this is meant as an unsuccessful attempt at literary hipness, or just an unfortunate reflection of the current text messaging generation, which is eschewing rules of grammar that for centuries have made text easier to read. Finally, there was one problem in the production of the book, and not its writing: Several of the pages had light brown spots on them that were apparently part of the paper, and not a result of post-production staining. But these may be limited to my particular (brand-new) copy of the book.

Readers interested in learning more about the book could start at the publisher's Web page, which features an online table of contents and index, all of the book's source code, two sample chapters (7 and 21) in PDF format, and a link for purchasing the electronic version of the book, also as a PDF file. Any road/code warriors who do development on their laptops, on the go, will appreciate having this book readily available.

Yet most of these objections are minor and easily fixable, and do not detract from the value of this book. I especially liked the depth of experience brought to each topic, and the authors' consideration of differing viewpoints. PHP in Action is a competent, engaging, and detailed discussion of object-oriented and agile programming principles that can help PHP developers boost their effectiveness and the quality of their code.

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

You can purchase PHP in Action: Objects, Design, Agility from amazon.com. Slashdot welcomes readers' book reviews -- to see your own review here, read the book review guidelines, then visit the submission page.

232 comments

  1. 3.... 2.....1.... by wellingtonsteve · · Score: 5, Funny

    Cue the PHP vs Every Other Language debate..

    1. Re:3.... 2.....1.... by Anonymous Coward · · Score: 2, Funny

      Visual Basic is so much better than PHP.

      Discuss.

    2. Re:3.... 2.....1.... by Anonymous Coward · · Score: 3, Funny

      I do all my scripting in Logo.

    3. Re:3.... 2.....1.... by wellingtonsteve · · Score: 1

      Personally I favour Haskell for web development

    4. Re:3.... 2.....1.... by Anonymous Coward · · Score: 0

      Visual Basic is so much better than PHP.

      Discuss.
      VB:
      Const visualBasicIsSoMuchBetterThanPhp as Boolean = True

      PHP:
      define("visualBasicIsSoMuchBetterThanPhp", True);

      Conclusion reached: VB is indeed better. Thanks for your attention.
    5. Re:3.... 2.....1.... by Anonymous Coward · · Score: 0

      And VB is so multi platform too. That is why it's the best. It's not named Visual Beginners All-Purpose Symbolic Instruction Code for nothing.

    6. Re:3.... 2.....1.... by Eudial · · Score: 2, Funny

      COBOL is the only really useful web language.

      --
      GAAH! MY PRINTER IS ON FIRE!!! PUT IT OUT! PUT IT OUT!
    7. Re:3.... 2.....1.... by HappyHead · · Score: 1

      Scheme can also be pretty fun for web development.

    8. Re:3.... 2.....1.... by gambolt · · Score: 2, Informative

      I've been playing with Keppler, a Lua web stack. It's surprisingly robust for how easy it is to get started with.

      http://www.keplerproject.org/wiki/US/HomePage

    9. Re:3.... 2.....1.... by Anonymous Coward · · Score: 0

      The Kepler folks sure are doing a fine job keeping anyone from using their framework due to the complete lack of any documentation or examples.

    10. Re:3.... 2.....1.... by Anonymous Coward · · Score: 0

      The problem with lua is that every minor version has it's own syntax and ABI. If you choose lua 5.x, you're pretty much stuck with that version. I did a simple lua sendfile binding in C that broke when I went from lua 5.0 - 5.1, IIRC the module loading changed too. Nekovm and Haxe or even parrot are better real world choices for web development.

      If I was looking to embed a language runtime, luaJIT would win.

    11. Re:3.... 2.....1.... by Anonymous Coward · · Score: 0

      PHP in Action: bugs, tears, sleepless sysadmins

    12. Re:3.... 2.....1.... by kalirion · · Score: 4, Funny

      I prefer Legos myself.

    13. Re:3.... 2.....1.... by Jansingal · · Score: 1

      and if there was documentation... u think anyone would read it :)

    14. Re:3.... 2.....1.... by Anonymous Coward · · Score: 2, Insightful

      For all the criticisms about PHP, I won't bite the hand that feeds me. It's widely available, easy to work with, in demand, and best of all, FOSS. I'm a businessman and a web designer, not a computer scientist. I think that anyone who gripes about PHP's shortcomings is just wasting their breath: It's not going away, it's been used for very large sites (see Facebook, Wikipedia, GoDaddy, etc.), and most of us find it to be a really great tool. It's not as though PHP gets in the way of developing with [insert language here].

    15. Re:3.... 2.....1.... by kryten_nl · · Score: 1

      If it can't be done with FORTRAN 77 it isn't worth doing.

      --
      For the perfect anti-Unix, write an OS that thinks it knows what you're doing better than you do and let it be wrong.
    16. Re:3.... 2.....1.... by Octopus · · Score: 1

      If you aren't programming enterprise Internets in Logo, WAYSA?

      * Why Are You Still Alive

    17. Re:3.... 2.....1.... by CastrTroy · · Score: 1

      If you're using VB.Net, it can be a lot better than PHP. First the .Net framework is a lot more easier to user than the 80,000 functions all under the same namespace of PHP. I also like that it's strongly typed, and compiled, but that's just personal preference. VB.Net is basically C# with different syntax. Also, Visual Studio is much better than any IDE I've ever seen for PHP. VB.Net isn't perfect, but I personally find it quite a bit easier to work in than PHP.

      --

      Anthropic principle: We see the universe the way it is because if it were different we would not be here to see it.
    18. Re:3.... 2.....1.... by Anonymous Coward · · Score: 2, Funny

      Fortran is for pussies who can't hack assembly.

      Java bytecode is good for quick prototyping of web portals though.

    19. Re:3.... 2.....1.... by wellingtonsteve · · Score: 1

      Well to be honest if you're not tapping out an HTTP response in 1s and 0s for each request you should be banned from Slashdot. Only the real nerds can hang out here.

    20. Re:3.... 2.....1.... by Anonymous Coward · · Score: 0

      I prefer assembler macros written in notepad.

    21. Re:3.... 2.....1.... by Heembo · · Score: 1

      I prefer x86 assembly language for all of my web development.

      --
      Horns are really just a broken halo.
    22. Re:3.... 2.....1.... by foniksonik · · Score: 1

      Doesn't that turtle get on your nerves? It's so slow. It takes forever when you give it a fractal equation to render;-p

      Logo was my first language... we used it in Kindergarten and First Grade as an intro to Computers in both Colorado and South Carolina (divorced parents).

      Ahhhh memories....

      --
      A fool throws a stone into a well and a thousand sages can not remove it.
    23. Re:3.... 2.....1.... by Anonymous Coward · · Score: 0

      It would be a (somewhat) useful language if it supported UTF-8. Natively.

    24. Re:3.... 2.....1.... by Sancho · · Score: 1

      My main problem with PHP is that it makes it extremely easy to code extremely poorly, and most PHP programmers make a lot of use out of that feature. It encourages mixing code and design, leading to difficult-to-manage websites (compare to any system which makes use of MVC.) This is also its greatest advantage--it's just so easy to add a ?php tag and some code for easy server-side scripting.

      CakePHP seems like a very neat idea--but then, when you're talking about a framework like this, it could really be done in any language. Why choose PHP (specifically) over Python or Perl if you're not going to use the main benefit of PHP (easy integration of design and code.)

      My next biggest complaint about PHP has to do with its types and casting, but realistically, that's something you can get over. Oh, and its lack of unsigned integers.

  2. 404 by daeg · · Score: 0, Troll

    404 when loading the publisher's website... I wonder if it's written in PHP?

    1. Re:404 by Anonymous Coward · · Score: 0
    2. Re:404 by Crudely_Indecent · · Score: 2, Informative
      --


      "Lame" - Galaxar
  3. PHP is For Newbs by Anonymous Coward · · Score: 1, Funny

    J/K. Programming bigots are all wankers in my book.

  4. Next release PHP will support ideas from 70s! by Anonymous Coward · · Score: 0

    In another 5 years we'll be able to run neural nets on PHP!

    1. Re:Next release PHP will support ideas from 70s! by ryanscottjones · · Score: 1

      In another 5 years we'll be able to run neural nets on PHP! What's stopping you from doing that now?
    2. Re:Next release PHP will support ideas from 70s! by Anonymous Coward · · Score: 0

      All languages support ideas from the 70s...and before. You really think object oriented programming is something new from the late 20th century?

  5. Slashdot allowing plain old advertisements now? by rgagnon · · Score: 1

    What a nice ad for a book. How'd this get past the firehose spam filtereing mods?

    1. Re:Slashdot allowing plain old advertisements now? by TheSpoom · · Score: 1

      Slashdot welcomes readers' book reviews -- to see your own review here, read the book review guidelines, then visit the submission page.
      And they have since I remember joining.

      There are stories here that make you wonder, but IMHO this isn't one of them.
      --
      It's better to vote for what you want and not get it than to vote for what you don't want and get it.
      - E. Debs
  6. Looks like a great book if you're stuck with PHP by bigtrike · · Score: 5, Informative

    This looks like a great book for those of us already stuck with PHP. For the rest, I'd suggest avoiding it entirely. PHP 5's OOP is still pretty awful and still has many caveats which have simply never existed in other languages. For example, the exception handling is pretty useless as it generates "Fatal error: Exception thrown without a stack frame in Unknown on line 0" when used in a number of contexts.

  7. PHP5 by corychristison · · Score: 5, Interesting

    But with the released of version 5, PHP introduced a robust object model, and made it easier for its proponents to create well-architected Web sites and applications.
    ... PHP 5 was released ~2.5 years ago. It MUST be noted that there were some significant changes in the 5.2.x branch. I don't see any mention of PHP 5.2 in this review. This book is already dated.

    I do web development & design for a living. I use PHP because it is what I got into and I have not yet had the time and/or drive to really try anything else. PHP is so available and that is its real strength. It's biggest problem is those lazy folks who are still running 4.2.x or some branch that is or is to be discontinued very soon here. As well there are some known exploits and issues in the older branches.

    I love the rapid-ness of PHP though. At present I even use PHP-GTK2 to prototype all of my idea's while I learn new languages. That is, I'll make a rough draft in PHP-GTK and then try to do the same in C/C++... which is much more painstaking for someone who has used web development for so long. But I am slowly un-learning my habits to depend on magic to handle memory for me, etc.

    Yup. Just my random bablings.. I am sure there was a reason I started writing this comment.
    1. Re:PHP5 by SanityInAnarchy · · Score: 1

      PHP is so available and that is its real strength. It's biggest problem is those lazy folks who are still running 4.2.x or some branch that is or is to be discontinued very soon here.

      You kind of contradicted yourself there. That, or PHP is much more pervasive than I give it credit for, such that even the 5.2.x branch is more widely deployed than everything else... but I kind of doubt that.

      I love the rapid-ness of PHP though. At present I even use PHP-GTK2 to prototype all of my idea's while I learn new languages. That is, I'll make a rough draft in PHP-GTK and then try to do the same in C/C++... which is much more painstaking for someone who has used web development for so long. But I am slowly un-learning my habits to depend on magic to handle memory for me, etc.

      You know, there's quite a lot besides PHP and C/C++. Not all of it makes you handle your own memory -- but you absolutely should have that experience of having to do that, so that you understand what's going on behind the scenes (why not to slurp the whole file, etc).

      --
      Don't thank God, thank a doctor!
    2. Re:PHP5 by garett_spencley · · Score: 1

      Not all of it makes you handle your own memory -- but you absolutely should have that experience of having to do that, so that you understand what's going on behind the scenes (why not to slurp the whole file, etc).

      Agreed. Even PHP developers should know about memory management. I use PHP all the time, I love it. But it can be just as dangerous as any other language. Functions like file_get_contents() are extremely convenient but also extremely stupid. It's kind of similar to C's strcpy() (only it won't cause a buffer overflow). If your php.ini file has sane a memory_limit setting then you're not going to crash the server. But an inexperienced programmer might not know any better and increase the limit to the available memory on the server and cause it to swap with something as simple as:

      $foo = file_get_contents(/path/to/sufficiently/large/file);

      or

      $foo = array();
      for($i = 0; $i 33554432; $i++) {
            $foo[$i] = $i;
      }

      etc.

    3. Re:PHP5 by corychristison · · Score: 1

      You kind of contradicted yourself there.
      I don't quite see the contradiction there, perhaps it was the way I worded it? What I meant to get across was that PHP 5.2 is the current stable branch and that there are some hosts out there that are still strictly only PHP4... despite some of the security issues.

      You know, there's quite a lot besides PHP and C/C++. Not all of it makes you handle your own memory -- but you absolutely should have that experience of having to do that, so that you understand what's going on behind the scenes (why not to slurp the whole file, etc).
      T'was just an example... I've dabbled with other languages as well (Python/PyGTK, TCL & TK, etc.) I just feel that C/C++ is a good route to go and am putting a lot more work into learning it because it allows a lot of control and fine-tuning in the event that I need it (yes, I know ASM is better, but also a steeper learning curve.)
    4. Re:PHP5 by jaydonnell · · Score: 1

      I haven't used php in years. Can you link to a page that highlights the significant changes in 5.2?

    5. Re:PHP5 by mbadolato · · Score: 1

      I haven't used php in years. Can you link to a page that highlights the significant changes in 5.2

      Did you even TRY to look for it yourself? I haven't used PHP in years either, yet I just went to php.net and right there in the second news entry on the front page, it announced 5.2.5 is released, and contains a link for Changelog for PHP 5. Boy that was hard.
    6. Re:PHP5 by jaydonnell · · Score: 1

      Thanks. I found those from google earlier, but when I read over those lists I don't see anythign that jumps out as somethign that would make the book different or that would warrant coverage. Which of those things are really cool new features? Did any change the way you do things?

    7. Re:PHP5 by corychristison · · Score: 1

      There wasn't anything that broke my code, however there have been a lot of enhancements (such as the changes in Datetime - in the upgrade guide link) which really speed up development. More extensions and improvements.. most of which involve OOP stuff.

    8. Re:PHP5 by jaydonnell · · Score: 1

      Yes, I did exactly that. However, the OP made it seem that there were some significant changes in 5.2 that somehow either made the book out of date or were so cool that they deserve mention in the book. Looking at the change log did not reveal such changes which is why I asked. Context is important my friend!

    9. Re:PHP5 by jaydonnell · · Score: 1

      which changes made the book dated?

    10. Re:PHP5 by BerntB · · Score: 1

      I use PHP because it is what I got into and I have not yet had the time and/or drive to really try anything else. PHP is so available and that is its real strength. It's biggest problem is those lazy folks who are still running 4.2.x or some branch that is or is to be discontinued very soon here. As well there are some known exploits and issues in the older branches.

      PHP's advantage is an easy learning curve, so it is easy to pickup (no cheap jokes about fat women, please). Larry Wall described that as [PHP] takes the worse-is-better approach to dazzling new depths.

      With that kind of raison d'être it shouldn't be surprising it is hard to get users to embrace new versions.

      --
      Karma: Excellent (My Karma? I wish...:-( )
    11. Re:PHP5 by Anonymous Coward · · Score: 0

      You can't be serious. You just can't be. Any coder who file_get_content's a 2GB file on a box with 512MB of RAM, and is surprised at the outcome, should NOT be a coder. Simple as that. Coding is supposed to require a little more brains than it takes to operate a goddamn toaster. If you have "an inexperienced programmer [who] might not know any better", you don't have a programmer - you have a toaster operator who thinks they can program because they've figured out how to use an "if" block.

      Of course every programmer should know the basics of memory, and bytes used by various data types, etc. But to label not requiring explicit memory allocation as stupid is... stupid. Oh my god... php lets you fill an array with 33,554,432 elements? How dangerous and stupid! Everyone, run for your lives!

    12. Re:PHP5 by SanityInAnarchy · · Score: 1

      You can't be serious. You just can't be. Any coder who file_get_content's a 2GB file on a box with 512MB of RAM, and is surprised at the outcome, should NOT be a coder.

      Or maybe they need to learn to be a coder.

      If you have "an inexperienced programmer [who] might not know any better", you don't have a programmer - you have a toaster operator who thinks they can program because they've figured out how to use an "if" block.

      You were born less than a toaster operator. You were born a smelly infant who couldn't do much other than shit, piss, and gurgle.

      Now, neither babies nor people who slurp multi-gig files should be paid professionals, but neither diapers nor crashing the server in your basement should mean there's no future for you, ever. We've all got some "rm -rf /" in our past.

      --
      Don't thank God, thank a doctor!
    13. Re:PHP5 by SanityInAnarchy · · Score: 1

      What I meant to get across was that PHP 5.2 is the current stable branch and that there are some hosts out there that are still strictly only PHP4... despite some of the security issues.

      True, but it still contradicts the point you made that it's "so available". Maybe it's how I'm reading it, but I took that to mean that every cheap web host in the world is going to have PHP somewhere -- but that's not much of a strength if you're counting all the PHP4 hosts in that statistic.

      it allows a lot of control and fine-tuning in the event that I need it (yes, I know ASM is better, but also a steeper learning curve.)

      Premature optimization is the root of all evil. Write your program in something reasonably fast (like Python), and add C and ASM as needed.

      Of course, this does mean you need to know C or ASM -- or that someone on your team does. I'd argue you need to know them more for understanding than for any practical purpose.

      --
      Don't thank God, thank a doctor!
    14. Re:PHP5 by aztracker1 · · Score: 1

      You're telling me.. while I'm not a fan of PHP, it does have it's uses, and is reasonably suited as a web development language/platform... I've always disliked the fact that most libraries for it are very C-Like, with everything being a global method... I will say it's very hard coming from a web development platform, even object/event driven ones, and work in a GUI world.. the extend of my gui development tends to go as far as configuration/automation tools, and not really much more...

      Which is funny, because bringing the same usability in a webapp is second nature to me... AJAX-style callbacks, and browser based scripting interacting with backend functionality on a web server, no problem... "getting" why only the main thread in a gui app can affect the gui directly... harder to do for some reason... lol.

      --
      Michael J. Ryan - tracker1.info
    15. Re:PHP5 by garett_spencley · · Score: 1

      But to label not requiring explicit memory allocation as stupid is... stupid.

      You misinterpreted my use of the word "stupid". I said it's akin to C's strcpy in that it doesn't know any better. That's not a bad thing. It's not "retarded" that the language has a function like that. But the function itself is dumb in that it doesn't know any better and the programmer needs to beware.

      Oh my god... php lets you fill an array with 33,554,432 elements? How dangerous and stupid! Everyone, run for your lives!

      I specifically chose that example because it's something that a lot of web developers might do. 33,554,432 4-byte integers is 128MB of data. On a production web server you could potentially cause trouble with something as innocent as that.

      I'm not sure if you're trolling or you really didn't understand what I was trying to say. The whole point of my post was to say that there are a lot of "web developers" who really don't know the first thing about memory management. I never said that PHP needs to be fixed, I said that those developers need a better understanding of what they're doing. PHP gets treated like a "toy language for dummies" a lot of the time but you need to know just as much about memory management to code in PHP as you do in C. A lot of "web developers" don't seem to get that. Especially those who's background is HTML/Javascript.

    16. Re:PHP5 by corychristison · · Score: 1

      The implementing of quite a few new features from 5.1 as well as 5.2. Apparently you did NOT look, as you would have noticed there were some syntax changes as well as many new features implemented and are included by default.

      Just shut up and read the change logs from the initial 5.0 launch that was years old. Read every change in all subsequent versions and maybe you will understand what I am talking about.

    17. Re:PHP5 by jaydonnell · · Score: 1

      why the hostility? The change log is very long and I asked a simple question about "significant" changes that were supposedly a "MUST" for such a book. I thought this sort of thing was the purpose of a discussion site!

  8. PHP needs more work by Anonymous Coward · · Score: 5, Insightful

    <?php
    function foo(){ return array(1=>'a', 2=>'b'); }
    echo foo()[1];
    ?>

    Parse error: syntax error, unexpected '[', expecting ',' or ';' in ... on line 3
    wtf?
    1. Re:PHP needs more work by corychristison · · Score: 5, Informative
      While what you may have not exected, there are many ways around this... the most simple of which:

      <?php

      function foo($get)
      {
      $array = array(1=>'a', 2=>'b');
      return $array[$get];
      }

      echo foo(1):

      ?>
      Which, in reality is cleaner in the first place. :-)
    2. Re:PHP needs more work by Azarael · · Score: 3, Informative

      If foo() is explode() or something similar though, you're out of luck. I expect that this is what the OP was referring to.

    3. Re:PHP needs more work by hardburn · · Score: 1

      No, gack, flasck, no.

      In practice, you almost never want to use only one element of an array. If you do, you probably actually wanted to use an associative array. Instead, you generally want to work over the complete array, such as with map, grep, or foreach (or whatever the PHP equivalents are).

      There are cases where you do need to index a specific array element (like sorting operations, and then only if you don't have a library that provides one for you), but these are the exception. You could have a useful programming language that doesn't have any array indexes at all.

      --
      Not a typewriter
    4. Re:PHP needs more work by nuzak · · Score: 2, Informative

      No, it's not cleaner in the slightest. Now you can't get at the whole array. Unless you want to overload the function. All that boilerplate because the designers of PHP still don't pay attention to basic things like this.

      Another workaround is to just use a temporary. Or a different language outright.

      --
      Done with slashdot, done with nerds, getting a life.
    5. Re:PHP needs more work by corychristison · · Score: 1
      From the example given (a simple echo) it was indeed a good replacement.

      <?php

      function foo( $get=chr(7) )
      {
      $array = array(1=>'a', 2=>'b');
      if( $get =! chr(7) )
      {
      return $array[$get];
      }
      return $array;
      }

      echo foo(1);
      // will echo 'a'

      // you may also use like so:
      list($item1, $item2) = foo();

      ?>
      This is usually pretty useful (in web design anyway) for configuration... as it is read only. If you need write, then what was the point of putting it in a function?
    6. Re:PHP needs more work by Anonymous Coward · · Score: 0

      list($v) = f();

    7. Re:PHP needs more work by Anonymous Coward · · Score: 0

      Sorry, If a function returns an array I should be able to dereference the returned value to get what I need without having to store the whole array. I ran into the problem the last time I used php. The memory is dim but I think that I needed to get the some aspect of a file in the filesystem and was using the built-in stat() function.

    8. Re:PHP needs more work by corychristison · · Score: 1

      $get =! chr(7)
      should have been:
      $get != chr(7)

      :-)

    9. Re:PHP needs more work by nicklott · · Score: 1

      Why would you expect that to work? That's just lazy programming. Using another few chars to assign what the function returns to another var isn't going to kill you, and the bytecode will come out the same.

    10. Re:PHP needs more work by thue · · Score: 1

      test.php
      <?php
      function f() {f();}
      f();
      ?>

      t@t ~> php test.php
      zsh: segmentation fault php test.php

      I had some fun with that when I accidentally introduced it while developing, and the webserver suddenly kept serving up blank pages.

      PHP catches almost all other kinds of user errors, and shows a nice error message, but when I reported this one they referred me to the manual and marked the bug report BOGUS. I still maintain that the interpreter crashing is not expected behaviour.

    11. Re:PHP needs more work by schneidafunk · · Score: 1

      don't knock the language simply because you don't know how to use it. 'a', 2=>'b'); } $array = foo(); echo $array[1]; ?>

      --
      Some people die at 25 and aren't buried until 75. -Benjamin Franklin
    12. Re:PHP needs more work by schneidafunk · · Score: 1

      woops, my code got clipped ... the original foo() function is fine, you just have to call it differently. as posted above: $array = foo(); echo $array[1];

      --
      Some people die at 25 and aren't buried until 75. -Benjamin Franklin
    13. Re:PHP needs more work by ratboy666 · · Score: 1

      Of course, what I find *really* fascinating is that PHP duplicates exactely a syntax error in SNOBOL4, but temporally shifted by 40 years...

      But, of course, SNOBOL4 was actually designed, and it had an "item(array,index)" function to correct this defect... I am sure that PHP *must* have something equivalent? (I am actually interested in the answer -- I am assuming PHP DOES have a solution that won't involve additional variables),

              define('foo()')
      * because "output = foo()[1]" won't compile -- same as PHP issue...
              output = item(foo(),1) :(end)
      * this also works, but is not in the spirit of the thing at all:
      * a = foo()
      * output = a[1] :(end)
      foo foo = array(2)
              foo[1] = 'a'
              foo[2] = 'b' :(return)
      end

      So, what have we learned in 40 years?

      --
      Just another "Cubible(sic) Joe" 2 17 3061
    14. Re:PHP needs more work by jonas_jonas · · Score: 1

      But you can with objects... ;-)

      <?php
          function foo(){
              return (object) array(
                  a => 1,
                  b => 2,
              );
          }
          echo foo()->a;
          echo foo()->b;
      ?>

      gives you:
      1
      2

    15. Re:PHP needs more work by mibus · · Score: 1

      Why would you expect that to work? That's just lazy programming. Using another few chars to assign what the function returns to another var isn't going to kill you, and the bytecode will come out the same.

      Why shouldn't it work? Yes, I'm lazy - I don't want to write an extra line in and have to think about a new name for a temporary variable, when I don't actually need the variable.

      I can't count how many times I have code like this:

      $row = mysql_fetch_array(mysql_query('SELECT COUNT(*) FROM mytable'));
      $thecount = $row[0];
      other_function ($thecount);
      instead of the long but still (IMHO) quite usable:

      other_function (mysql_fetch_array(mysql_query('SELECT COUNT(*) FROM mytable'))[0]);
      Sure, it's not pretty. 90% of the time, I don't really care because I'll never see the code again. (Much of what I do is throw-away or so short maintenance isn't an issue).

      While I'm ranting - create_function() sucks. Quotes!? :)
    16. Re:PHP needs more work by Anonymous Coward · · Score: 0

      No, it's not cleaner in the slightest. Now you can't get at the whole array.

      It is cleaner...there is no return type or casting.
      If you want a function to return a reference, have it return a reference. Assume you can dereference the array just because a typesafe language can is silly.
    17. Re:PHP needs more work by BrynM · · Score: 1
      You've got to use two functions, but you can do this:

      <?php
      function bar() {
      $array = array(1=>'a', 2=>'b');
      return $array;
      }

      echo "bar = " . array_search( '1', array_flip( bar() ) ) . PHP_EOL;
      // will echo 'bar = a'
      ?>
      No extra vars at all. You will get a RAM spike if bar() contains a sufficiently large array though. Odd thing to do just to get no variables, but I love a challenge :)
      --
      US Democracy:The best person for the job (among These pre-selected choices...)
    18. Re:PHP needs more work by Anthony+Boyd · · Score: 1

      I have to admit, I'm kind of glad that PHP doesn't let you do that. This is kind of a Perl-ish mindset, that everything that can be consolidated should be. It makes for dense code. I'll take PHP's limitations here, as they seem to be a bonus for readability.

    19. Re:PHP needs more work by Halcyonandon · · Score: 1
      Hm, I dunno, I can achieve the same result with much cleaner code:

      <?php echo 'a'; ?>
      ;-)
      --
      ^o^
    20. Re:PHP needs more work by muszek · · Score: 1
      bringing the luck back to you, mate:

      function my_explode($delimiter,$string,$key) {
        $array = explode($delimiter,$string);
        return $array($key);
      }
      echo my_explode('.','a.b.c',1); // b
    21. Re:PHP needs more work by Anonymous Coward · · Score: 0

      Unless you want to overload the function Which you can't do in PHP...
    22. Re:PHP needs more work by Azarael · · Score: 1

      That's fine if you have time to write wrappers for every function that returns arrays ;-)

    23. Re:PHP needs more work by xhrit · · Score: 1

      Most ov the time I write wrappers for every php function just to get rid ov the stupid function names and inconsistent argument orders.

      coming soon to php6, from teh makers ov explode() : kaboom(), kaPow(), pew_pew_pew() ** and chaChing()!

      **note: different function then pew_pew()

    24. Re:PHP needs more work by Azarael · · Score: 1

      You should release those as a library.

  9. English, do you speak it? by Anonymous Coward · · Score: 1, Funny

    In turn, the new OOP capabilities have facilitated additional best practices, such as design patterns, test-driven development, continual refactoring, and HTML templates.


    Bingo, sir.
    1. Re:English, do you speak it? by Metasquares · · Score: 1

      "Best practices" is a misnomer anyway. It implies that the aforementioned software development practices are somehow optimal. If this is as good as software engineering can ever get, we're in trouble!

  10. ISBNs by Anonymous Coward · · Score: 1, Informative

    "under the ISBNs 1932394753 and 978-1932394757"

    The former is a traditional ISBN. The latter is what was (or is) called a Bookland EAN (978 is like a country code you'd find in any EAN, specifying that the rest of the numbers make up an ISBN.) They're both ISBNs now, as ISBN space expansion necessitated reformatting, but I guess my point is that, while they're different formats, they represent the same ISBN. The review makes it sound like they're different printings.

  11. Stuck? by AutopsyReport · · Score: 2, Insightful

    Get over it. PHP is not perfect, but it does a damn good job. If it didn't, it wouldn't be so widely used. You can respectfully disagree, but try to maintain some civility here instead of suggesting we all just avoid PHP as if it's some kind of curse. There isn't a tool in the world that doesn't have it's flaws.

    I've been using PHP for eight years and there hasn't been a day where I wished I had chosen another language. Sure, I wish the PHP of today was available eight years ago, but I can't complain with what is available now.

    --

    For he today that sheds his blood with me shall be my brother.

    1. Re:Stuck? by LuckyStarr · · Score: 5, Interesting

      I've been using PHP for eight years and there hasn't been a day where I wished I had chosen another language. Sure, I wish the PHP of today was available eight years ago, but I can't complain with what is available now.
      That makes me wonder what other languages beside PHP you know.
      --
      Meme of the day: I browse "Disable Sigs: Checked". So should you.
    2. Re:Stuck? by Samus · · Score: 5, Funny

      Get over it. GWB is not perfect, but he does a damn good job. If he didn't, he wouldn't be so widely loved. You can respectfully disagree, but try to maintain some civility here instead of suggesting we all just avoid GWB as if he's some kind of curse. There isn't a tool in the world that doesn't have his flaws.

      I've been praising GWB for eight years and there hasn't been a day where I wished I had chosen another president. Sure, I wish the economy of eight years ago was available today, but I can't complain with what is available now. Just a parody. I'm not trying to turn this thread political. Laugh or don't laugh then move on.
      --
      In Republican America phones tap you.
    3. Re:Stuck? by deanoaz · · Score: 1

      Parent makes good points.

      --
      If 'the people' in Amendment 2 are 'the state' then Amendments 1, 2, 4, 9, and 10 benefit the state, not you.
    4. Re:Stuck? by dubl-u · · Score: 2, Insightful

      Get over it. PHP is not perfect, but it does a damn good job. If it didn't, it wouldn't be so widely used.

      Yes, all things that are popular are good and work well! Windows 3.1 and Visual Basic were very popular. So was the belief that the earth is flat. And there's chlamydia. That's hella popular.

      I've been using PHP for eight years and there hasn't been a day where I wished I had chosen another language.

      No offense, but if you've been using the same language for eight years without any regrets, I don't see you as having enough perspective to offer up much useful information.

      As far as I can tell, PHP is popular because it's perfectly adequate language for cranking out some basic dynamic pages, and it's very easy to learn and set up. However, just like Visual Basic, the things that make it useful in the shallow end of the pool keep it from being useful at scale. And from the eternal trickle of security issues and the host of weird issues with it, it was apparently designed by amateurs.

      If you're happy with it, that's awesome. Carry on. Just don't get your knickers in a twist because a lot of people correctly see it as the wrong tool for their jobs.

    5. Re:Stuck? by PresidentEnder · · Score: 1

      Indeed. I'm tired of hearing about how Clinton made the economy work so well. Can anyone tell me exactly what he did?

      --
      I used to carry a bottle of whiskey for snake bite. And two snakes. -Nefarious Wheel
    6. Re:Stuck? by alex4u2nv · · Score: 1

      I think thats what a lot of developers are failing to realize. That one "shoe" doesn't fit all, and that you need the right tool for the job.

      For instance, you can't take out your drain plug with a hammer, but who says it can't be done with a lot of work?
      So to, you won't build a website you plan on dumping on easily available webhost on Java.
      You're not going to tackle something as tedious as google's finance app with javascript, etc. But thats not saying it can't be done without a lot of work.

      So as a developer, your "tool" isn't VI, or the IDE, or compilers. Your ultimate toolsets are your languages.

    7. Re:Stuck? by Anonymous Coward · · Score: 0

      In a way it could be said that he continued on the path set by Regan in reigning in the deficit. Sure the surplus wasn't exactly a true surplus but it was better than cutting taxes and going to war (twice) on said phony surplus. Would Gore have done any better in the face of the dotcom bust? We'll never know for sure but its doubtful we'd be fighting a war on multiple fronts right now.

    8. Re:Stuck? by Anonymous Coward · · Score: 0

      To start with, he didn't spend $1b/day fighting a war that didn't, strictly speaking, need to be fought. Even Bush senior ensured that the first Iraq war was paid for by a coalition. He even publicly cautioned his son about unilaterally financing the war during the buildup to the war, and was basically ignored.

      Whether the war should have been fought is, at least, debatable. You can (IMHO, unconvincingly) make an argument that Saddam needed to be deposed. What is not debatable is how crippling to our economy the war has been. It's the single biggest factor in the looming recession (which actually stands a pretty good chance of being a full-blown depression, depending on which economists you believe).

      The first step for the next administration to start the process of fixing the economy will be to collect more money than they spend and to ensure that what money they do spend is not spent on things that will not help the economy. This can either take the form of the liberal "raise taxes to support spending" or the conservative "lower spending to be in line with desired taxes." But the neo-conservative "lower taxes and spend more" is a recipe for disaster, and we're about to experience the disaster of the past 8 years.

    9. Re:Stuck? by Anonymous Coward · · Score: 0

      I thought you were talking about GW-Basic until I read the 'president' word.

    10. Re:Stuck? by PresidentEnder · · Score: 1

      I'm not a fan of Bush. You've made ad hominem attacks against someone I already despise. Now, defend Clinton.

      --
      I used to carry a bottle of whiskey for snake bite. And two snakes. -Nefarious Wheel
    11. Re:Stuck? by Rick+BigNail · · Score: 1

      While I am not a fan of PHP, you need to argue what else you use instead which is so much better than PHP.

      Perl? Python?

    12. Re:Stuck? by Gulthek · · Score: 1

      Google, so easy anyone can do it!

      Search terms: clinton economics

      Clinton Economics

      Enjoy.

    13. Re:Stuck? by dubl-u · · Score: 1

      you need to argue what else you use instead which is so much better than PHP.

      No, I don't need to argue that.

      My point is that you should use the right tool for the job. The guy I replied to is one of many people who only has one tool in his toolbox: PHP. In my view, that makes him either a novice or a dolt. I'm ok with novices: they know they need to learn more, and eventually do. The dolts, on the other hand, are beyond my power to help.

    14. Re:Stuck? by AutopsyReport · · Score: 1

      So because I said I've been using PHP for 8 years, that is conclusive evidence that I don't know any other languages? Great line of thinking, pal.

      I can be certain if my response listed C++ instead of PHP, you wouldn't question me the way you have. PHP, to you and many others, has the unfortunate distinction of assuming that everyone who uses it is useless, uninformed, and lost in their ways. This is far from the truth for many of those who make a living in PHP development.

      --

      For he today that sheds his blood with me shall be my brother.

    15. Re:Stuck? by AutopsyReport · · Score: 2, Informative

      No offense, but if you've been using the same language for eight years without any regrets, I don't see you as having enough perspective to offer up much useful information.

      So my career path, which lead to developing in a specific language, has somehow excluded me from being eligible to offer up any "useful information"? Where is the logic in that?

      As far as I can tell, PHP is popular because it's perfectly adequate language for cranking out some basic dynamic pages, and it's very easy to learn and set up. However, just like Visual Basic, the things that make it useful in the shallow end of the pool keep it from being useful at scale. And from the eternal trickle of security issues and the host of weird issues with it, it was apparently designed by amateurs.

      By the sounds of it you hardly have a grasp on what PHP can and cannot do, yet you're using your limited knowledge as basis to challenge my credibility? Brilliant...

      And on a technical note, if you're suggesting PHP cannot scale, I advise you to reach just how scalable it is. You can start by informing yourself with how Wikipedia operates.

      --

      For he today that sheds his blood with me shall be my brother.

    16. Re:Stuck? by Sancho · · Score: 1

      Personally, if you said you were using C++ for server-side CGI, I'd think you were crazy!

      I think one of the reasons that PHP has such a stigma associated with it is because there are a lot of really bad PHP programmers dumping out really bad code. Sure, it's possible to produce elegant PHP. I'm of the opinion, though, that PHP makes that difficult. There's a certain elegance to separating your code from your output (in this case, from the HTML you generate.) PHP doesn't make it easy to do that. For example, I think I've seen exactly one (out of many) open-source PHP projects which made use of templating. Most of them just output raw HTML (and lots of it) with PHP echo statements. That's just awful and unmaintainable.

      There's very little wrong with PHP from a design perspective. It has crappy typing/casting, but that's a design decision. It has hacks like === (which wouldn't be necessary if it had better typing!) And its objects leave a lot to be desired, but then, object oriented programming isn't the end-all be-all, anyway. Other than that, I can't think of anything particularly egregious about the design of the language. It's primarily the way people use it that gives it such a bad name.

    17. Re:Stuck? by Joe+Mucchiello · · Score: 1

      For example, I think I've seen exactly one (out of many) open-source PHP projects which made use of templating.

      Well since the one I like uses templating you must mean Geeklog (@ geeklog.net)

    18. Re:Stuck? by LuckyStarr · · Score: 1

      So because I said I've been using PHP for 8 years, that is conclusive evidence that I don't know any other languages? Great line of thinking, pal.
      No. That after using it for 8 years, you're still so happy with it that you care to defend it.

      I disagree with Sancho though, I have indeed strong objections against the language itself and not only the implementation. Just curious, how often do you have to look up the PHP manual on a common day? Have a look at http://tnx.nl/php.

      C++ is a different beast though. There are orders of magnitude more possibilities to shoot yourself into the foot with C++ than with PHP. It's very hard to write and even harder to read. Given the complexity of C++ I can understand that a language with a built-in garbage collector and a simple (in comparison to C++) syntax may seem like salvation. But PHP ain't it.
      --
      Meme of the day: I browse "Disable Sigs: Checked". So should you.
    19. Re:Stuck? by dubl-u · · Score: 1

      So my career path, which lead to developing in a specific language, has somehow excluded me from being eligible to offer up any "useful information"? Where is the logic in that?

      Your career path has prevented you from offering useful information on all sorts of things. Industrial cooking, counseling drug addicts, and waste recycling are probably among them. Unfortunately, one of those things is the relative merits of different languages. Sorry if the truth hurts.

      You saying PHP is totally awesome is like somebody who has never traveled saying their country is the best one in the world. Hell, they even could be right, but they don't have enough perspective to make me expect that they'll have anything interesting to say.

      And on a technical note, if you're suggesting PHP cannot scale, I advise you to reach just how scalable it is. You can start by informing yourself with how Wikipedia operates.

      Thanks, I already know how it operates. I know that they struggle to introduce new features, and have for years. I know that a lot of key code is not in PHP, but rather in C++, as the PHP was way too slow for them. And I know that they are stuck in the same design ghetto that traps a lot of two-tier applications that need to scale, not just in traffic volume, but in complexity.

      About the best high-volume use I've seen for PHP is the same approach as Facebook: relatively basic front-end code in PHP, with all serious development work done in other languages as services that the PHP calls via APIs. At which point, its technical handicaps don't matter much, and it's just another page templating language. Except that you have a big pool of cheap front-end developers to hire from.

      And of course, it's fine for all of those 5-10 page dynamic web sites in the world, too. A cheap solution is just the thing for people with limited needs and small budgets. In that space, I'm all for PHP.

    20. Re:Stuck? by AutopsyReport · · Score: 1

      I never claimed PHP was awesome, but I did say that it isn't so bad that people need to discourage others from using it. You're responses are so riddled with assumptions and misinformation, you're already wasted too much of my time.

      --

      For he today that sheds his blood with me shall be my brother.

    21. Re:Stuck? by dubl-u · · Score: 1

      I did say that it isn't so bad that people need to discourage others from using it.

      And that's where you're wrong. Like any tool, it's good for some jobs, bad for others. For the latter, people should be actively discouraged from using it, as the ease of getting something quick and basic out gives them a false sense of security about the greater effort. As a few of my clients have discovered to their cost.

      You're responses are so riddled with assumptions and misinformation, you're already wasted too much of my time.

      Classic. Taking extra time to tell me I'm a waste of time? Sounds like it's not so much about your busy schedule.

    22. Re:Stuck? by Rick+BigNail · · Score: 1

      Well, you did compare PHP with Visual Basic.

    23. Re:Stuck? by barnetwc · · Score: 1
      First, in the spirit of full disclosure, I use PHP but prefer Ruby.

      Yes, all things that are popular are good and work well!
      Sarcasm aside, using this logic Van Gogh should never have picked up a paintbrush because a billion talentless painters had done so before him.

      No offense, but if you've been using the same language for eight years without any regrets, I don't see you as having enough perspective to offer up much useful information.
      I don't recall the original poster saying anything to the affect of "I've only ever used PHP for eight years." Furthermore, the thought that someone with as many years experience would not have something useful to say is equally ludicrous.

      As far as I can tell, PHP is popular because it's perfectly adequate language for cranking out some basic dynamic pages, and it's very easy to learn and set up. However, just like Visual Basic, the things that make it useful in the shallow end of the pool keep it from being useful at scale.
      Not the scale issue again! Someone's not been keeping up with their reading. "Basic, dynamic pages" like Flickr, Yahoo, and Wikipedia are fairly popular. I for one wouldn't mind having the scaling problems of these sites.

      the eternal trickle of security issues
      Means an eternal trickle of security fixes and is a product more of PHP's widespread use than poor design.

      apparently designed by amateurs
      Which segues perfectly to something I'm almost too embarassed to call to your attention... Isn't that how many great open source projects get their start?! I don't know why I let the haters bait me but it troubles me when I see those wishing to increase knowledge denegrated by others.
  12. yeah right by mrsbrisby · · Score: 3, Insightful

    PHP has for much of its history been criticized for not offering the full capabilities of object-oriented programming (OOP).
    Yeah, that's exactly why it's criticized. It has nothing to do with the fact it takes them three releases to fix a simple integer overflow, that they thought "safe_mode" was an access control system, that "require" pulls in files unexpectedly from malicious sites. It has nothing to do with the fact that mysql_connect() takes arguments, and programmers are encouraged to use mysql_connect() in a way that makes it incompatible with the default mysql install. It has nothing to do with the fact that regular expressions are so prevalent and yet there is no syntax for them. It has nothing to do with the fact that the language mutates drastically with toplevel global configuration variables.

    Seriously, it has nothing to do with the fact we're sick and tired of cleaning scripts written by people who don't know what they're doing, and we like blocking access to your site for major vulnerabilities. We actually love it how when your script gets owned, you don't notice for months because you do the development on the server, all the while jerkoffs are udp-flooding from your site. Because you'll never pay for this usage, and you'll expect us to fix your script, it doesn't matter because we're just really upset that it isn't "offerring the full capibilities of object-oriented programming".

    That and we sometimes wonder what it would be like to fling poo...
    1. Re:yeah right by SirSlud · · Score: 1

      That and we sometimes wonder what it would be like to fling poo...

      Well, there's always the option of becoming a Perl developer. ;)

      --
      "Old man yells at systemd"
    2. Re:yeah right by loki.TJ · · Score: 1

      Actually,

      As far as I know, you can't require() a file from a server other than the one that the current file was requested from. So your statements about "require() pulls in files unexpectedly from malicious sites" is completely false.

      As to "programmers are encouraged to use mysql_connect()", well that might be in your neck of the woods. By my 2nd year of development I had written a custom connection class to handle it all, protect the data from injection and do any number of modelling that I needed it to.

      "Regular expressions are so prevalent"??? I have written stuff for Google Maps, Inform's API, CakePHP, e107, phpbb, punbb, and hundreds of other php junk and used regular expression maybe once. Could you please list any php app package that uses them heavily?

    3. Re:yeah right by rho · · Score: 1

      Sure, and those are all valid complaints.

      Yet PHP continues to be used by some of the most popular sites. Why is that?

      I think because PHP *is* easy and approachable, and so when some guy has an idea for something he just starts building it. He doesn't have to hire a Java programmer at $80K a year to tell him how his idea is not going to work.

      --
      Potato chips are a by-yourself food.
    4. Re:yeah right by mrsbrisby · · Score: 1

      As far as I know, you can't require() a file from a server other than the one that the current file was requested from.
      Then you don't know very well. allow_url_include was introduced in php version 5.2. All versions prior to that (Except versions earler than 4.3.0 on windows) in fact operate exactly as I specify.

      So your statements about "require() pulls in files unexpectedly from malicious sites" is completely false.
      Only completely not.

      As to "programmers are encouraged to use mysql_connect()", well that might be in your neck of the woods. By my 2nd year of development I had written a custom connection class to handle it all, protect the data from injection and do any number of modelling that I needed it to.
      Stop doing that. There's no reason to write a custom connection class for Mysql. There are plenty already, and you're probably doing it wrong. mysql_connect() is supposed to connect to a unix-domain socket, not an IP address. Using IP for mysql is slower, and a security risk. If your "custom connection class" requires a hostname, it's wrong.

      "Regular expressions are so prevalent"??? I have written stuff for Google Maps, Inform's API, CakePHP, e107, phpbb, punbb, and hundreds of other php junk and used regular expression maybe once. Could you please list any php app package that uses them heavily?
      How about phpbb? How about cakephp?
    5. Re:yeah right by mrsbrisby · · Score: 1

      Yet PHP continues to be used by some of the most popular sites. Why is that?
      Worse is better.

      I think because PHP *is* easy and approachable, and so when some guy has an idea for something he just starts building it. He doesn't have to hire a Java programmer at $80K a year to tell him how his idea is not going to work.
      That's an interesting way to look at it.

      I would look at it differently: If I wanted to be successful, would I use the same tools that all those unsuccessful people are using? Or would I use the tools that the successful people are using?
    6. Re:yeah right by loki.TJ · · Score: 1
      mrsbrisby,

      Then you don't know very well. allow_url_include was introduced in php version 5.2. All versions prior to that (Except versions earler than 4.3.0 on windows) in fact operate exactly as I specify.

      Off by default. If you are experienced enough to turn it on, hopefully you are aware of the dangers of including files via a url.

      Only completely not.

      Welcome to 2008. That article was written in 2005 and talks about a security issue with libcurl, not with the require() function. Of course there are security concerns if you are CURL'ing a file. But that's still not an issue with the standard require() function.

      Using IP for mysql is slower, and a security risk

      This has nothing to do with the original post saying there are issues with allowing developer access to the db via mysql_connect(). But, please, show me data that says using an IP address (127.0.0.1) is less secure than localhost.

      How about phpbb? How about cakephp?

      Again. You give extremely limited examples. I didn't say those packages didn't use regex. The original post said that PHP is flawed because it uses large amounts of it and I said that I doubt that. And again, your example shows a few lines in packages that are almost hundreds of files.
    7. Re:yeah right by Anonymous Coward · · Score: 0

      My criticism of PHP is that it's just a very poorly implemented copy of Microsoft's old-fashioned ASP model. Even if the language and implementation didn't suck, the model is still ancient and clunky. Heck, even Microsoft abandoned the ASP model in favor of ASP.NET over 6 years ago.

    8. Re:yeah right by BrynM · · Score: 1

      mysql_connect() is supposed to connect to a unix-domain socket, not an IP address.
      Got a reference for that? From the php manual:

      resource mysql_connect ([ string $server [, string $username [, string $password [, bool $new_link [, int $client_flags ]]]]] )
      Opens or reuses a connection to a MySQL server.
      Parameters
      server
      The MySQL server. It can also include a port number. e.g. "hostname:port" or a path to a local socket e.g. ":/path/to/socket" for the localhost.
      If the PHP directive mysql.default_host is undefined (default), then the default value is 'localhost:3306'. In SQL safe mode, this parameter is ignored and value 'localhost:3306' is always used.
      ...
      Socket based connections weren't added until 3.x.
      --
      US Democracy:The best person for the job (among These pre-selected choices...)
    9. Re:yeah right by mrsbrisby · · Score: 1

      As far as I know, you can't require() a file from a server other than the one that the current file was requested from.
      ...

      Off by default. If you are experienced enough to turn it on, hopefully you are aware of the dangers of including files via a url.
      Man up. You were wrong. You said PHP in a standard configuration can't read files over the network. Either you knew about it or you didn't, and it doesn't really matter which. You know now.

      please, show me data that says using an IP address (127.0.0.1) is less secure than localhost.
      I didn't say that. I said it was less secure than a unix-domain socket. An SSH user can disable their password so only an SSH key can be used to login. That user can disable access to their mysql image by TCP meaning that the only way to gain access to that mysql image is by breaking their account.

      It's more secure than a password which can be brute-forced, and it can even be attacked by sideways vectors- maybe someone was able to read one of your files- something very common in a shared-hosting image. Any other user of that system could instruct apache to read out your database config file and steal your mysql password.

      "Regular expressions are so prevalent"??? I have written stuff for Google Maps, Inform's API, CakePHP, e107, phpbb, punbb, and hundreds of other php junk and used regular expression maybe once. Could you please list any php app package that uses them heavily?
      ...

      Again. You give extremely limited examples. I didn't say those packages didn't use regex. The original post said that PHP is flawed because it uses large amounts of it and I said that I doubt that. And again, your example shows a few lines in packages that are almost hundreds of files.
      You can always argue whatever criterea you want for "large amounts of it". I never said anything about large amounts, nor size, simply that it was prevalent. That means that it is found or existing everywhere, not that the source files are mostly regular expressions.
    10. Re:yeah right by mrsbrisby · · Score: 1

      mysql_connect() is supposed to connect to a unix-domain socket, not an IP address.
      Got a reference for that?
      Sure.

      From the MySQL manual says that will pull in defaults from my.cnf which by default indicates a unix-domain socket for access.

      If you call mysql_connect() with no arguments, it does this. The additional arguments are for backwards compatability- they shouldn't be used in new programs. I recommend instead people rely on PHP's runtime configuration to specify the behavior of mysql as it makes it much easier to manage your application.

      Socket based connections weren't added until 3.x.
      PHP versions prior to PHP 3.0.10 are irrelevant. Nobody should be using PHP 3.0.10 for new programs.
    11. Re:yeah right by mrsbrisby · · Score: 1

      My criticism of PHP is that it's just a very poorly implemented copy of Microsoft's old-fashioned ASP model.
      PHP/FI came out in 1995, while ASP came out in 1996.

      Even if the language and implementation didn't suck, the model is still ancient and clunky. Heck, even Microsoft abandoned the ASP model in favor of ASP.NET over 6 years ago.
      Well, not really. ASP.NET still makes many of the same mistakes that PHP does. While yes, it is possible to separate code and data for application, session, and documents, it still is easier to avoid making the distinction. This makes it impossible to tell what's a "safe" url, and to adequately describe what a document can do. PHP tried to introduce "safe mode" and "magic quoting", but because the semantics are simply too complicated for the people who need php to "just be easy", they don't get used, and because they don't get used, they don't save anybody anything. It's 2008 and new programs are still requiring register globals.

      However, draconian approaches are possible: I wrote SiteSafe specifically to deal with this: Most PHP applications don't need to access the filesystem. They use MySQL calls so any access to the filesystem (besides sessions) is either the author updating the site, or its an attacker who has broken your application. SiteSafe can fix this problem easily by simply denying access to the filesystem.

      PHP could do something more portably: Require a permissions mask be encoded at the top of every php tag that says what permissions would be required for the block. For example, <?php f=fopen("foo.txt","r") ?> could become <?php[open-existing-file-read] f=fopen("foo.txt","r") ?>. This would encourage programmers to do less in each block, and include better semantic signatures. Including all permissions would be more typing than they would ordinarily be willing, and automated tools could be made trivially to establish risk-vectors for PHP applications. Any attempt to set these permissions sitewide would put a red box at the top of every page that says This application is running with increased privileges so that the application author would be encouraged to audit and fix their application.

      Of course, PHP developers don't know how to add two numbers so I doubt this would ever happen...
    12. Re:yeah right by loki.TJ · · Score: 1

      Man up. You were wrong. You said PHP in a standard configuration can't read files over the network.
      Actually, I said that PHP can't include files using require() from domains other than the one that is serving the requested file. I never mentioned network or standard configuration. You mentioned php conf setting, and I stated that the settings you were naming are off by default. I won't even argue the rest. Mainly because "sideways vectors" is not a term I have ever heard used with mysql or php programming. I'll mark this as a win, although you know what they say about winning an argument online.
    13. Re:yeah right by mrsbrisby · · Score: 1

      Actually, I said that PHP can't include files using require() from domains other than the one that is serving the requested file.
      And you were wrong. PHP by default operated this way for a very long time, and had this as its documented behavior.

      I stated that the settings you were naming are off by default.
      Oh bullshit. First of all, the settings didn't used to be disabled by default- that's rather new. Bad engineering is bad engineering- it doesn't go away.

      Apparently my comment went right over your head. I'll be more direct: Other people criticise PHP because you don't understand the little corner cases like this. Once they've been declared fixed, you conveniently forget any memory of there ever having been a problem. Because you don't know them, you'll deploy an application - broken by higher standards, and you will not know how to fix it. The php developers won't know how to fix it either because they're not any smarter than you are. Meanwhile, my servers will get hammered with udp floods from your attacker. You will cause me grief, and you'll weasel your way out of responsibility like you're doing right now.

      you know what they say about winning an argument online.
      that at least I'm not Chris Thompson?
    14. Re:yeah right by loki.TJ · · Score: 1

      Oh my god. You know me name. Please, where will I hide. You're right. You are smarter than me. I'm sorry for ever challenging you to an online debate.

  13. Where to start out language wise? by poetmatt · · Score: 1

    As a complete programming noob looking to get into web-related design and things of that nature, what languages are good to start with and to branch to other languages? Would that be like C-> PHP -> SQL? What other languages apply and/or in what order are languages needed to learn to start to bring things together for well designed websites?

    1. Re:Where to start out language wise? by Azarael · · Score: 1

      These days you can insert Python and quite a few other languages into the middle slot (D also comes to mind). I'd suggest just doing some searching around the net to see if you can find something that suits you.

    2. Re:Where to start out language wise? by pahoran · · Score: 1

      It doesn't really matter. What matters is that you learn _how_ to program well. This comes with time and experience. Going to school or reading a _lot_ of books can reduce the amount of time required to gain experience.

      If you want to get started fast with web sites use PHP. Accept the fact that you won't know too much about how much is happening under the hood, but you will still get things that run. You will start to build experience.

      If you can accept a slower pace, then start with C. You'll learn a lot more about how things work (mostly by shooting yourself in the foot alot).

      If you want to get started really quickly and really never know what you're doing, use Rails.

      If you don't want to try any of those, try another one.

      Hmm, SQL ... it is not a procedural language so it doesn't compare well to C or PHP. Learn about different types of languages if you're interested in the differences. If you want to interface with relational databases you'll probably need to know SQL. If you don't know what a relational database is then either read about them (or don't if you never think you're going to write apps that use them).

      Also, realize that when you start you probably aren't going to code very efficiently or securely. Don't put any information near your web server that you care about too much.

      --
      I'd give my right arm to be ambidextrous.
    3. Re:Where to start out language wise? by hal9000(jr) · · Score: 1

      Definetly learn SQL. You will need it. PHP is easy enough to learn and you can start making dynamic web apps quickly. You do want to find some good books and sites that discuss PHP programming. You don't need to know other languages.

    4. Re:Where to start out language wise? by nuzak · · Score: 1

      Java. Yes, it's a craptastic language, but you wanted web development, and until you at least know something about JavaEE, if only to have educated reasons to hate it, a good chunk of potential clients see you as swimming in the kiddie pool. Plus, you get to branch to other languages that are actually a pleasure, like Scala.

      --
      Done with slashdot, done with nerds, getting a life.
    5. Re:Where to start out language wise? by poetmatt · · Score: 1

      I plan to go book-hunting and slashdot folk definitely know programming well so I'm glad I asked :) I don't expect this overnight, I just want a good idea of where to start. I was going to try C, but other than arrays and basic system calls I didn't really take much away from it...which I was dumbfounded by because I couldn't figure out how a language that is a large basis of many OS's (feel free to correct me if I am misinformed on that)...seemed to do not much more than basic manipulation of tables, arrays, etc.

      Thank you for the security advice and all the rest too...would it be sufficient to run a virtual machine of the server without an exceptional knowledge of security or would my home/office system be too easily compromised even if its in a sandbox?

    6. Re:Where to start out language wise? by Anonymous Coward · · Score: 0

      C -> Smalltalk -> Smalltalk -> Smalltalk -> Smalltalk (notice a theme)
      C -> Smalltalk -> Lisp
      C -> Smalltalk -> Erlang

      done.

      PHP - duh. Avoid like the plague. This doesn't even qualify as a language, just a hacked together set of web libraries. No PHP is not object-oriented. See Smalltalk or Lisp.

      C# - Nice language, awful web framework, MS bs. Good development environment. Fixes a lot of what is wrong with Java, but at the expense of less good, free libraries.

      Java - yuck for productivity, lots of examples of how not to do web development. A giant mess all around, avoid like the plague. Still, there are some great libraries available and it's widely supported.

      Python - Not bad, but wants to be like Smalltalk or Lisp, yet fails miserably. Many weird conventions, broken pieces (threading), and confused libraries. Well supported though and a pleasure to develop in vs. Java and C#. A better choice than Ruby by light years for similar development.

      Ruby - Incomplete. Use Python if you want something like this but with a stronger base. Don't be tempted by the Rails nonsense. Great for command line scripts, not so much for big time real development. Give it a few more years. If you don't see the fundamental problems in this language, you have no business programming. The language can be fixed, but it will take time.

      Smalltalk - An actual object oriented language. Makes Java, C#, and even Ruby look procedural. It also has the single best and most productive development environment.

      Lisp - Makes Smalltalk look procedural, but annoying to read and development environment sucks.

      Erlang - Holy moses. Wish it had more support and a better development environment.

    7. Re:Where to start out language wise? by avi33 · · Score: 1

      Well, I hate to go back to the dreaded car analogy, but C -> PHP -> SQL is a bit like saying you should learn mechanical engineering before you learn to change the oil in your car, then learn how to back it out of the driveway.

      If you have nothing but brains and time, C will be a great start...managing references vs. pointers and memory...you will be bulletproof when you start using a 21st century language. Not to start a flamewar here, but maybe it's useful in plenty of ways (mostly learning how freaking hard it was to program 40 years ago), I'm sure a bunch of people will jump down my throat and tell me I wouldn't be able to wake up in the morning and make it to my coffee machine without using C 12 times. My point is, it's hard, and not exactly a recommended place to start if you just want to build web sites. If you want to major in Computer Science, on the other hand...have at it.

      Let's skip ahead to SQL. It's doesn't matter what language you "program" in, SQL is what you use to put and get data in and out of a database. 95% of the time, it's "Select [something] from [tablename] where [parameter] equals "whatever"... or a similar insert/update statement. Hordes, and I mean HORDES of sites use little more than that, but you can obviously go hog wild in this department and become an Oracle DBA and make piles of money if you like.

      As far as a programming language to render pages and interact with a database? There are dozens of legitimate choices, and whichever one you pick, you will have millions of people agreeing with you or derisively calling you an idiot. Some people think java is robust and "enterprise" - some think it blows. PHP has some issues pointed out clearly above, but I've used it for basic web development and never ran into any problems (or had a site 0wned). c# or asp/vbscript is easyish (but widely hated on here), and you might need a $10,000 OS/product suite to run it on your own hardware (but obviously you can find that environment at any hosting company). Ruby, Python, Perl, whatever...advocates and critics abound. Keep in mind, you learn a lot from the code you borrow/find on the web, so if you pick an obscure language, you might make life harder down the road. i.e. Lisp might be the most perfect language ever designed, according to some, but if I needed "sample code" to rip off for my own web development efforts, I can't imagine finding a decent function after googling for ten minutes. Not so with php etc. (Of course, you'll also find some *bad* functions too!)

      I'd look for 'tutorials' or 'getting started' and probably start with PHP or python. Actually, I'd spend a few days on 3-4 different ones...they'll all start off doing the same thing, and you might find that one is just easier to look at and comprehend. Look up LAMP (Linux/Apache/MySQL/PHP/Python) and you'll find loads of stuff.

      Let the flames begin, I'm a "web developer" and not a "software engineer" - this is slashdot after all - but you asked.

    8. Re:Where to start out language wise? by Phrogman · · Score: 1

      Despite its naysayers - and hey this wouldn't be slashdot if you mentioned a programming/scripting language and dozen people didn't immediately post about how bad the language in question was - PHP is an excellent introduction to web-based programming. Sure, there are other approaches you can take, which may even be far better, Ruby, Python, Java etc, but with PHP you can accomplish something and start learning in very short order and there is still a lot to absorb. I think its a good way to learn programming for the web. I can build something in PHP in a fraction of the time it would take me in Java, and to be honest (IMHO) I think the result is just as effective to the user. PHP is easy to learn, effective enough, and not a bad place to start. At least you will have something to compare it to when you try out other languages down the road.

      --
      "The first time I got drunk, I got married. The second time I bought a chimpanzee, after that I stayed sober" Arian Seid
    9. Re:Where to start out language wise? by pahoran · · Score: 1

      Hmm, that is an interesting question.... I think you might know more than you're letting on. :)

      I think you would be all right as long as you didn't let the virtual machine that your server is running on know about the existence of your home/office hard drive partition. To be really safe I'd use a separate physical machine as your web server and lock it out of the rest of your home/office network, but I tend to be labeled paranoid.

      As far as C goes ... its power is in its libraries, not in the basic language constructs. Those libraries are a bit hard to learn, though, and things like file I/O are more straightforward in PHP or Python. This is because (in C) you are really only one level of abstraction above the assembler and so things tend to be a bit more tedious. With practice, though, you can knock out C code just about as fast as PHP code. Personally, I think the increased knowledge of how lower-level parts of the system work is worth the price.

      You might try playing with C++ and the STL if you want to mix low-level power with some higher-level tools like file streams, strings, templates, etc. Java has been advocated in this thread, but you don't get enough low-level freedom with it, in my Humble but Accurate opinion. :) That said, Java works great for many things -- I just personally prefer C++.

      Usually when I have a web app that needs a powerful piece I write all but the that piece in Python or PHP. The powerful piece is usually in C++ and the front end calls the back end when it needs some heavy lifting done. This requires an intimate knowledge of what your web server is going to do and where the less efficient parts of execution are.

      You can also configure your web _server_ to do some of its tasks more efficiently using ISAPI (IIS) or modules (Apache). These pieces almost always are written in C or C++.

      My rule of thumb is:
      1. When it has to be written fast or I don't need to optimize it much I use Python or PHP (most web programming falls into this category).
      2. When I need to tweak lower level components I use C++. Usually I write non-web applications in C++. If there are portions of a web app that could gain speed from C++, I write those portions in C++.
      3. When I need to optimize A LOT I usually take something written in C++ and refactor parts of it into C to make it faster.

      Some crazy (or highly motivated) people add a step 4 and refactor portions of their C code into assembly code to make things screaming fast.

      --
      I'd give my right arm to be ambidextrous.
    10. Re:Where to start out language wise? by poetmatt · · Score: 1

      I didn't intend for C-> PHP -> SQL, I was asking if there such a chain. I am asking what that chain would be :) So yes, I want to learn the oil change before becoming the aeronautic pilot and do the steps imbetween as well.

      With that said, thank you very much for your explanation :) It does answer the kinds of questions I was looking to answer, as many others have done (thankfully).

    11. Re:Where to start out language wise? by oliderid · · Score: 1

      I have developped web services with Perl, PHP, C#, Java and I tried Python for fun.

      If you don't know HTML, Javascript CSS learn them First.

      I'd certainly consider PHP as a good starting point...Why?

      - You can easily play with PHP on most Linux distribution without any difficulties. Most of the time PHP is part of the default web server package. (same for Perl but usally it requires additionnal installation like DBI if you want to play with database)
      - Syntax is quite simple and almost as flexible as Perl (almost...)
      - Most Hosting companies provide PHP in their basic contract (Perl isn't as common as it used to be surprisingly, Python isn't yet).
      - Tons of references/tutorial/forums over the web.

      If you don't know basic security rules (chmod, user's right and all), try to find a book related to basic Unix/Linux files management.

      Once you master them, I really suggest to make the next step...And try C# or Java. If you want to make a living of web development...There are ten PHP web developers for one Java web developer (IMHO), Java usually means big projects with big money and long term contracts.

    12. Re:Where to start out language wise? by Anonymous Coward · · Score: 0

      IMO, for web development:

      Python (and Django--maybe one of the other options, but I recommend Django)
      XHTML+CSS (markup, not programming, but essential. Even if all of your sites are totally programmatically-generated, you need to know what's correct to tell the program to generate correct things.)
      SQL
      C (if you need anything computation-heavy done, you can call it from Python)

    13. Re:Where to start out language wise? by Anonymous Coward · · Score: 0

      C, for web design? You've got to be joking me. Let's introduce the common bugs on the desktop in a (hopefully) cross-brower, cross-operating system fashion. PHP, is acceptable. SQL is nothing like the other two. Please at least do a little research (Google, Wikipedia, etc.) before asking questions like that.

    14. Re:Where to start out language wise? by CastrTroy · · Score: 1

      And definitely ignore all the tutorials on the web and avoid mysql_ functions. Use PDO. It lets you do paramterized queries which is the actual correct way to guard against sql injection, along with increasing speed. Using PDO will also let you switch to another database without changing every line in your database code. You may still need to tweak some queries, but at least you won't have to change every line of code.

      --

      Anthropic principle: We see the universe the way it is because if it were different we would not be here to see it.
    15. Re:Where to start out language wise? by mrsbrisby · · Score: 1

      As a complete programming noob looking to get into web-related design and things of that nature, what languages are good to start with and to branch to other languages? Would that be like C-> PHP -> SQL? What other languages apply and/or in what order are languages needed to learn to start to bring things together for well designed websites?
      Stop looking at languages that way. They aren't like spoken languages- you cannot realistically speak one well enough to make up for the fact you can't speak any other. Programming languages are designed around the different shapes of algorithms- some programmers refer to these as patterns. Ideally, each language contributes some optimal representation of a pattern, and if it doesn't, you have to wonder about the usefulness of the language- especially more so if it isn't any more useful at anything than any other language.

      Learn to read. A good way to do this is to learn Lisp (CL). It has no syntax to speak of, so you will be forced to grasp well the concepts behind programming. You can introduce language features as it becomes necessary, they have an excellent development environment, and it's easy to build web applications with it. You don't even have to download anything, you can try it right now.
    16. Re:Where to start out language wise? by aztracker1 · · Score: 1

      FYI, there are a few other options for C# for web development not using the ASP.Net model.. probably the best example is monorail.. you get the benefits of an MVC web development platform without a lot of the issues in trying to configure tomcat/eclipse etc (shudder)... also, MS's MVC framework will allow you to pretty much replace any point in the mvc stack with your own.

      To each their own.. I hate MS's politics, but really like VS2005-2008 and c#... really wish they'd have inline regular expressions though... linq additions to 3.5 would have imho been a good time/place to add them.. le sigh.

      I think ruby is okay, the performance really isn't there though, and scaling gets difficult. emphatically not a fan of php though.. really wish there weren't so many halfway decent (from a user/usability standpoint, not code) web applications written in it.

      --
      Michael J. Ryan - tracker1.info
    17. Re:Where to start out language wise? by poetmatt · · Score: 1

      Ha, thanks. I know some. Any knowledge so I can learn more is of infinite value to me, so the responses to my OP is beyond invaluable to me now (and bookmarked). I just never took things to their capability with programming because in all honestly, I meant what I said as literally as possible: oftimes I just never knew where to start. I've heard all manner of programming languages mentioned before (python, c, OpenGL, etc), and I grew up on the computers like any good slashie (I broke some air pilot/bomber polygon game by fiddling with its code at about 5 years old....we're talking like loading programs on floppies era), even spent childhood playing pole position and LP/Lima Muds, which I programmed on briefly...hell, one of my family friends was a very active part of Ground Zero and some other black hat group with a nuclear-style name back in the day.

      I don't even know how to create sandboxes/virtual machines but I have read up some...I was actually trying to figure out how to run a VM of windows XP under linux using an existing windows XP partition but I couldn't figure out how to do it. It seems that there are issues with swap and memory even with 3 gigs of ram on an E6700....my idea there was to run native XP under linux to test for gaming (which I have no idea if its viable or not vs Cedega and other programs I couldn't figure out when I Tried last).

      What is STL? Also I looked into the PHP/Apache/IIS thing and it seems like I need to understand more than just PHP to use PHP and/or even test it, right? Aka I have to at least figure out some basics of Apache as well?

      I think my next step is to start exploring and/or finding some good forums to plod through, but thank you for all the information.

    18. Re:Where to start out language wise? by pahoran · · Score: 1

      Ah yes, the floppies era... back when floppies were floppy.

      STL = The Standard Template Library.

      Learning how C++ templates work has a bit of a long learning curve attached to it, but they are very powerful and tend to be more efficient than equivalent constructs in scripting languages or Java. They are also easier to write than equivalent constructs in C.

      Setting up PHP is pretty easy on IIS -- you download the installer from php's web site. For Apache it's easy on all package-based Linux flavors I've ever used ... just add the php package. If you have a different situation then happy reading / compiling.

      Setting up PHP _securely_ is a different story. There are some tweaks and hoops to jump through. Reading up on secure web server configuration (in general, not just for PHP) might be good to do at some point. Reading up on secure programming also might be a good idea (any time you program in C/C++ to make something screaming fast you have to be much more careful about doing it The Right Way).

      One thing I should probably mention -- when I say screaming fast I mean it. Most stuff doesn't need to be that fast. Usually you need C/C++ when doing:
      1. Heavy duty math e.g graphics or game programming or scientific computing.
      2. LOTS of device I/O: #1 is an example -- another would be writing your own database: this requires you to have very low-level access to memory and the hard disk in order to optimize resource usage.
      3. Direct interaction with an embedded system like a cell or a PDA or your web-controllable robot.
      4. Writing device drivers for an OS like Linux or writing OS modules for same.

      If you never envision needing to do things like that you may never need to delve too deep into C/C++ -- HOWEVER, I'd still take some pains to learn how C pointers and handles work because that is probably the single most useful thing that you can do to know what you're scripting engine is doing with your data structures under the covers (speaking of which, I'd learn what how to use a C struct and how to use a POINTER to a C struct and the difference between the . and -> operators). #2 thing I would do is learn the anatomy of a process: especially The Stack and The Heap. Learn what it means to allocate a variable on the stack vs on the heap vs where static variables get allocated.

      --
      I'd give my right arm to be ambidextrous.
  14. I've said it before and I'll say it again: by Anonymous Coward · · Score: 3, Funny

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

    1. Re:I've said it before and I'll say it again: by Anonymous Coward · · Score: 0

      I prefer "PHP: Training wheels without the bike."

  15. "robust object model??" by Maxmin · · Score: 5, Insightful

    PHP introduced a robust object model, and made it easier for its proponents to create well-architected Web sites and applications.

    While I agree with the latter overall, I dispute "robust object model." What's missing? Polymorphism is sketchy, and static initializers are missing, for two. In PHP5, you can only initialize static properties with literals or constants - no function or method calls.

    Also, calling up the inheritance chain, to a grandparent class's implementation of a method, is difficult to say the least.

    While PHP5 is a *lot* better than PHP4 (and probably Perl if one took the time to compare) - it's not really comparable to truly robust OOP languages such as Java, Smalltalk and C++.

    Mind you, I code in PHP5 for a living. It gets the job done, but it has to be called on its limitations, and you gotta be honest and tell programmers who want OOP from PHP5 that it has limits, and how to work around them. None of this "robust object model" stuff.

    --
    O lord, bless this thy holy hand grenade, that with it thou mayest blow thine enemies to tiny bits, in thy mercy.
    1. Re:"robust object model??" by SanityInAnarchy · · Score: 1

      While PHP5 is a *lot* better than PHP4 (and probably Perl if one took the time to compare) - it's not really comparable to truly robust OOP languages such as Java, Smalltalk and C++.

      How is it better than Perl?

      I'll admit Perl's OOP is weird. It's weird syntactically, it's weird conceptually, it feels bolted on, etc.

      But scratch the surface a bit -- it's also every bit as powerful as Java or C++. Moreso, I'd say, especially if you like "duck typing" (to steal a Ruby term).

      --
      Don't thank God, thank a doctor!
    2. Re:"robust object model??" by nuzak · · Score: 1

      > static initializers are missing

      I come to bury PHP with a backhoe, not to praise it, but: why on earth does it actually need static initializers? PHP code runs as a script. You just stick the initialization code in the script.

      --
      Done with slashdot, done with nerds, getting a life.
    3. Re:"robust object model??" by Bob9113 · · Score: 1

      Mind you, I code in PHP5 for a living. It gets the job done, but it has to be called on its limitations, and you gotta be honest and tell programmers who want OOP from PHP5 that it has limits, and how to work around them. None of this "robust object model" stuff.

      As a long-time OO programmer who has been baptized by fire over the past two months in PHP, I strongly concur with your sentiment. PHP is another good tool to have in the tool box, and the OO is decent but a little short of full-blown. Your suggestion that people be prepared for the reasonable limitations in PHP OO is a sound one. Well said.

    4. Re:"robust object model??" by Maxmin · · Score: 1

      Haha - well, that's a good point, but one I won't concede due to my long-lived habits. =)

      Some static properties you only want to initialize once, and they're not singletons or the like, so you don't necessarily want to trigger their initialization through the constructor. I suppose you could wrap the static initializer code in another static method, then call that method from the bottom of the .php file that defines the class. I have a recollection that there are problems with that.

      --
      O lord, bless this thy holy hand grenade, that with it thou mayest blow thine enemies to tiny bits, in thy mercy.
    5. Re:"robust object model??" by Anonymous Coward · · Score: 1, Insightful
      While PHP5 is a *lot* better than PHP4 (and probably Perl if one took the time to compare)

      Go ahead, I'll wait ...

    6. Re:"robust object model??" by Maxmin · · Score: 1

      For coding, I find PHP5's syntax clearer - verbose keywords are the key, for me. For usage, I find Perl's better - simply require/use a module, instantiate, use, etc. Plus, the CPAN archive of modules and classes is outstanding.

      However, I feel about Perl's OO the way I feel about Javascript's - it's syntactically weird, as you say, and not verbose enough for me. Too much implied through context and operators, not enough spelled out. That said, I tough it out and work with 'em both.

      For Javascript, syntax is apparently going more verbose in the next major ECMA release... if I understand this correctly.

      --
      O lord, bless this thy holy hand grenade, that with it thou mayest blow thine enemies to tiny bits, in thy mercy.
    7. Re:"robust object model??" by tknd · · Score: 1

      Too much implied through context and operators, not enough spelled out.

      There's nothing stopping you from being more verbose in perl.

      For example I typically write my plain functions like this:

      sub add($$) # (x, y)
      {
      my $x = shift;
      my $y = shift;

      return $x + $y;
      }

      While I could have easily gotten away with:

      sub add($$) { $_[0] + $_[1]; }

      which actually turns out to be faster but not very easy for the unexperienced to read or maintain.

      As such I reserve non-verbose and awkward code for special situations (needs optimization, needs to go fast) but I tried to be verbose in all other cases.

      I do wish there were more ways to restrict definitions of function and method parameters (argument prototyping only applies to plain non-OO style calls) and that the OO was better defined not just hashes and bless. But I find for now, it does allow me to implement OO designs with minimal language barriers.

      I don't remember PHP but I do remember an awful lot of limitations on the OO model. Some of the limitations turned me away from PHP quickly.

    8. Re:"robust object model??" by Anonymous Coward · · Score: 0

      Perl's object model is so vastly different from most programming languages that I don't know how you would compare them.

    9. Re:"robust object model??" by edeloso · · Score: 1

      That's the solution that I've found to work... so far. It feels in the border between kludge and hack, but it seems pretty stable. The main thing to remember, I believe, is that the class scripts will get rerun on each execution, the definitions don't persist in the session like I originally expected. To be noted, I'm still quite 'young' in PHP, and was trying to recreate some functionality I was comfortable with from Objective-C.

    10. Re:"robust object model??" by SanityInAnarchy · · Score: 1

      I generally prefer something like:

      sub add {
      my ($x, $y) = @_;
      return $x + $y;
      }

      However, the one-line example you listed is the kind of thing I might use as a callback. Sometimes, I just can't resist overly-clever, completely unreadable one-liners.

      --
      Don't thank God, thank a doctor!
  16. That's not why it's been criticized. by SanityInAnarchy · · Score: 4, Insightful

    PHP has for much of its history been criticized for not offering the full capabilities of object-oriented programming (OOP).

    Nope. PHP has been criticized for:

    • starting out as insecure by default
    • lacking the basic capabilities of most other languages -- not just OOP, but things like anonymous subroutines
    • being designed around the need to embed code in a template (not a good idea -- separate content from logic from presentation!)
    • having essentially nothing compelling to offer once other languages got said templating ability -- but sensibly as an add-on, not as a core feature of the language (all PHP files, even library code, must be sandwiched between <?php and ?>)

    I could go on. Not all of these are really legitimate complaints, or a reason not to use the language; indeed, it has evolved. Due to the amount of code that exists in PHP, and the amount of cheap hosting which runs some form of PHP, I can no longer accuse people of being stupid for choosing PHP, although I might call them insane for liking it if they've given anything else half a chance.

    But I wouldn't put a lack of basic OOP particularly high on the list, especially with how dysfunctional the OOP was when it was finally added.

    Disclaimer: As much as I enjoy flamewars, and although I realize this will feed one, that's not why I'm posting. I'm just posting to clarify -- if you thought all PHP needed was OOP, you're dead wrong. If you're trying to improve PHP, look beyond OOP. (Look especially to the mysql_add_slashes_no_really_i_mean_it_this_time() functions, and compare them to Perl's support for prepared queries.)

    --
    Don't thank God, thank a doctor!
    1. Re:That's not why it's been criticized. by fredrik70 · · Score: 1

      but they *do* have anonymous functions, with the create_function() call.
      The annoying thing is though that the function will not get cleared from memory once if goes out of scope, making it leak memory. great.

      --
      if (!signature) { throw std::runtime_error("No sig!"); }
    2. Re:That's not why it's been criticized. by __aanonl8035 · · Score: 1
    3. Re:That's not why it's been criticized. by jimdread · · Score: 1

      You mean like mysqli_stmt_prepare ? Looks pretty much like PERL's version

      Looking at the examples you linked to, the difference between PHP and Perl in database operations is pretty clear. The PHP function is called mysqli_stmt_prepare, making it obvious that it only works with MySQL. Presumably the code would have to be changed to postgresqli_stmt_prepare,(or whatever the PostgreSQL function is called) if the database was changed from MySQL to PostgreSQL.

      Compare that with the Perl version, in which the only difference between code that connects to a MySQL database or a PostgreSQL database is the datasource string. That's the string in your second linked web page that says: "DBI:mysql:database=somedb;host=localhost". For this code to be connected to a PostgreSQL database, that might change to "dbi:Pg:dbname=foo", and the code would then work with PostgreSQL. And the same thing can be done to connect to just about any other database.

      That difference alone might be enough to make me want to use Perl in preference to PHP. However, once you start using some Perl modules, the programming job becomes much easier. For example, a lot of PHP code still contains many SQL statements for inserting, finding, updating, and deleting data. Using Perl's DBIx::Class module for example, the programmer will probably not need to write any SQL statements in the program. The module will handle it all. Removing most of the SQL from the program means that a big source of bugs and other problems is gone. And it removes the SQL injection attack problem too as a bonus.

      Clearly Perl isn't for everybody. It can be difficult to understand how to use the power of Perl to produce good programs. But once you do understand that, the deficiencies of some other languages become apparent. However, if people want to use PHP for whatever purpose, then good luck to them. I hope it works out well. If somebody likes PHP and doesn't want to change, then they should stick with it. If it does what you want and you're happy using it, then it's clearly a good choice for you.

    4. Re:That's not why it's been criticized. by CastrTroy · · Score: 2, Informative

      That's why you use the PDO functions and stay away from the mysql_ and pgsql_ functions. It lets you code without being tired to any specific database. It lets you run queries against MS SQL Server, PostgreSQL, MySQL, Oracle, ODBC, SQL Lite, and a few other databases.

      --

      Anthropic principle: We see the universe the way it is because if it were different we would not be here to see it.
    5. Re:That's not why it's been criticized. by SanityInAnarchy · · Score: 1

      Pretty much.

      I should have been clear -- a lot of the criticism of PHP is for historical reasons. But they are kind of valid historical reasons, because a lot of people do still code like that.

      But you can probably build a decent API on top of most Turing-complete languages.

      --
      Don't thank God, thank a doctor!
    6. Re:That's not why it's been criticized. by smellotron · · Score: 1

      starting out as insecure by default

      I agree. Sucks. Also generally requires sysadmin-level permissions in order to change basic configuration such as error reporting, error level, magic quotes, etc. Starting from a stock OS install, it probably takes me about half an hour to get a PHP installation into a reasonable "default" state.

      Come to think of it, reminds me of setting CXXFLAGS in my Makefile to include -Wall -Wextra -Wno-reorder -Werror -march=pentium4 -minline-all-stringops -ffast-math -O2 -ggdb. Even the Java JVM has fairly important tuning parameters (the most common solution to Eclipse performance problems back when I used it was "give it most of your system memory, and close it when you're done coding"). It's hard to create a flexible system without introducing bootstrapping complexity, and it requires up-front planning that simply wasn't a part of PHP's history.

      lacking the basic capabilities of most other languages -- not just OOP, but things like anonymous subroutines

      Take a look at the "decorate-sort-undecorate" idiom in PHP; it speaks for itself.
      function functional_sort($array) { sort($array); return $array; }
      function make_sort_key($datum) { return -$datum; }
      $original = array(1, 2, 3, 4, 5, 6, 7);
      $sorted = array_map( create_function('$tuple', 'return $tuple[0];'),
      array_map( 'functional_sort',
      array_map( create_function('$single', 'return array(make_sort_key($single), $single);'),
      $original )));
      Apologies for syntax errors, that's off the top of my head. Anyone who says PHP can't be used for functional programming is just not creative enough. The correct answer is that PHP can be used as a functional language, but it probably shouldn't be used that way (as you can clearly see).

      being designed around the need to embed code in a template (not a good idea -- separate content from logic from presentation!)

      I actually do have a beef with this. I find PHP's method of output more natural than something like a C or C++ program where you have to explicitly manage I/O. The fact that it can be horribly abused is no worse than the fact that any program in any other language can horribly abuse I/O. All of the (recent) PHP output I've written is as well-organized as any template-based system, thankyouverymuch.

      having essentially nothing compelling to offer once other languages got said templating ability

      PHP offered me something. Dirt simple installation and a very easy migration path from static HTML pages to something dynamic. That may not be much use for a lot of people, but I find it very natural for creating interfaces. While systems like Django are enticing, I'll probably stick with PHP for my small home-server apps just because of the learning curve.

    7. Re:That's not why it's been criticized. by SanityInAnarchy · · Score: 1
      Come to think of it, reminds me of setting CXXFLAGS in my Makefile to include -Wall -Wextra -Wno-reorder -Werror -march=pentium4 -minline-all-stringops -ffast-math -O2 -ggdb.

      None of what you just described has anything to do with your actual code, or even its capabilities. Those are warnings, development options, and performance tuning.

      And, were you to find a host who'd allow arbitrary executables, you could still set all that. Were you to find a host who'd allow arbitrary C, none of the flags you've set there actually affect the outcome.

      Contrast this to PHP, where basic things like the maximum file upload size (a capability) and whether or not to automatically set query string variables to language variables (changes source compatibility) are global, language-wide, server-wide config options.

      Anyone who says PHP can't be used for functional programming is just not creative enough.

      Yeah, another poster mentioned create_function. They also mentioned that it leaks memory.

      I actually do have a beef with this. I find PHP's method of output more natural than something like a C or C++ program where you have to explicitly manage I/O.

      And if all it did was IO, that would be fine.

      The fact that it can be horribly abused is no worse than the fact that any program in any other language can horribly abuse I/O.

      More like it was designed to be horribly abused.

      I mean, I assume you're talking about providing HTML output by putting ?> <b>some text here</b> <?php in the middle of your program. But how is that not explicit? It's just explicit in a really perverse way.

      All of the (recent) PHP output I've written is as well-organized as any template-based system, thankyouverymuch.

      Great -- and is your program code that well-organized? Do you cleanly separate your logic from your presentation, so your designers can tweak the template -- or swap it wholesale, or make your app skinnable -- without you having to lift a finger on the real code?

      If you answered "yes", there's no reason you couldn't have done the same with Ruby and ERB, or Perl and TemplateToolkit, or...

      If you answered "no", you're probably one of the people abusing it.

      PHP offered me something. Dirt simple installation and a very easy migration path from static HTML pages to something dynamic.

      And that is why it has been criticized -- if you go from static pages to PHP, there's a chance your PHP scripts are horribly designed.

      I'd also argue that even systems like CGI or mod_perl are about as easy, for the few places I need something dynamic. When it's just a template system, I'll use something like a Perl script and static files.

      --
      Don't thank God, thank a doctor!
    8. Re:That's not why it's been criticized. by smellotron · · Score: 1

      Anyone who says PHP can't be used for functional programming is just not creative enough.
      Yeah, another poster mentioned create_function. They also mentioned that it leaks memory.\

      Sorry, I may not have expressed my opinion strongly enough with the tone of my voice. Functional programming in PHP sucks. create_function sucks. The only saving grace for "decorate-sort-undecorate" in PHP is that it's significantly faster than the version with custom comparisons... because function calls are sooo slowwww in PHP.

      I actually do have a beef with this. I find PHP's method of output more natural than something like a C or C++ program where you have to explicitly manage I/O.
      And if all it did was IO, that would be fine.

      I'm not sure I get you. What does ?> ...stuff... <?php do besides I/O?

      Do you cleanly separate your logic from your presentation, so your designers can tweak the template -- or swap it wholesale, or make your app skinnable -- without you having to lift a finger on the real code? ...If you answered "no", you're probably one of the people abusing it.

      Due to the nature of the projects where I use PHP, I am both the developer and the designer. So no, I don't use a separate "templating language", because I am comfortable using PHP for both "templates" and "programs". Yes, I do separate "skins" into separate PHP scripts, which are then include()ed with a distinct set of parameters. It's up to my own discipline to make sure that the "business logic" goes in the scripts, and the "display logic" goes into the templates. If you think it's abuse, you are misunderstanding what I am doing.

      ...that is why it has been criticized -- if you go from static pages to PHP, there's a chance your PHP scripts are horribly designed.

      That statement is meaningless, because there's always a chance your script/program is horribly designed. I'm guessing you meant to say that a bad design is more likely via an evolutionary process like static HTML -> PHP. In that matter, the nature of PHP is both a strength and a weakness—People who suck at programming would be equally bad using a more complex framework. Your tool can't make people stop sucking, because you have to be smart enough to use it right. PHP does hit a power ceiling faster (it takes more effort and discipline to keep a large PHP project clean than a large Django/RoR/Java Servlet project), but that by itself doesn't deserve criticism. See Worse is Better for a better description of why the low power level provided by PHP is not a failure.

      I'd also argue that even systems like CGI or mod_perl are about as easy, for the few places I need something dynamic. When it's just a template system, I'll use something like a Perl script and static files.

      CGI and mod_perl fit on the same level as PHP, in my book. Choose whatever you're comfortable with; no one else cares, as long as you don't expose it in your URLs. I'll keep on using PHP, because I know how to write secure code with PHP, and I don't care to spend the time learning the equivalent in Perl (but maybe C++, now that you mention it).

    9. Re:That's not why it's been criticized. by smellotron · · Score: 1

      For example, a lot of PHP code still contains many SQL statements for inserting, finding, updating, and deleting data. Using Perl's DBIx::Class module for example, the programmer will probably not need to write any SQL statements in the program. The module will handle it all. Removing most of the SQL from the program means that a big source of bugs and other problems is gone.

      My limited experience with DBIx was that it generated horrible SQL for large data listings, several orders of magnitude worse than basic SQL SELECT statements with joins... I don't know how it compares to other ORM tools like what Django or Ruby on Rails use, or Python's SQLAlchemy. It's possible that it wasn't DBIx, but the programmer using it incorrectly; enlighten me if I'm wrong. Myself, I tend to prefer using the database for more than "object persistence", so I use hand-crafted SQL for most cases. Of course, basic single-table CRUD isn't worth hand-crafting, but it takes 20 minutes to write a set of CRUD functions that convert between associative arrays and SQL statements. Using prepared statements, I've never found SQL to be a source of bugs. More often, it's something inane like a mistyped variable name, or actual incorrect logic, but not usually a mistyped SQL query (because they get copied and pasted from my psql prompt once I know they're correct).

      And it removes the SQL injection attack problem too as a bonus.

      SQL injection attacks are a non-issue with proper management of character encoding and something like Perl's DBI or PHP's PDO. You shouldn't need an ORM tool (which is what DBIx is) to protect yourself against SQL injection attacks.

    10. Re:That's not why it's been criticized. by SanityInAnarchy · · Score: 1

      I'm not sure I get you. What does ?> ...stuff...

      That's the point...

      You see, what I meant was, if all PHP did was IO, that would be fine. But when people start using PHP as a general-purpose programming language, I call it a bad idea. It would be like writing a language in which OpenGL primitives were included -- where you had a specific symbol and syntax for a triangle, or a quad...

      It's up to my own discipline to make sure that the "business logic" goes in the scripts, and the "display logic" goes into the templates.

      But with that pattern, I honestly don't see the point of PHP over any other scripting language with strong template systems built on it.

      I'm guessing you meant to say that a bad design is more likely via an evolutionary process like static HTML -> PHP. In that matter, the nature of PHP is both a strength and a weaknessPeople who suck at programming would be equally bad using a more complex framework.

      Could be. I'd hope that a better-designed framework -- not necessarily more complex -- would force people to think in a different way. It is possible to write perfectly modular code based on GOTOs, but I wouldn't recommend it, certainly if you're trying to teach someone to program.

      --
      Don't thank God, thank a doctor!
    11. Re:That's not why it's been criticized. by smellotron · · Score: 1

      You see, what I meant was, if all PHP did was IO, that would be fine. But when people start using PHP as a general-purpose programming language, I call it a bad idea. It would be like writing a language in which OpenGL primitives were included—where you had a specific symbol and syntax for a triangle, or a quad...

      Ok, I understand you now. Yeah, it is sort of a kludge to consider that a general-purpose programming language has special syntax for using stdout... but it's not uncommon. PHP's domain originated in producing HTML content, where such a syntax makes sense. It should be avoided in library files or command-line scripts where there isn't an expectation of producing "content" while executing. I don't see this as any different than Perl having built-in regular expressions or $_, or any shell using stdin/stdout as a value-passing mechanism. Heck, we could do away entirely with printf() and just use fprintf(stdout, ...) for the C standard library. But people have decided that the special case is a common idiom, and worth keeping.

      As to a language based around OpenGL/graphics primitives... the Alias|Wavefront OBJ file format is a declarative form of just that. It wouldn't suprise me to see someone use an embedded Lua interpreter to create a procedural "file format" for graphics primitives.

      It's up to my own discipline to make sure that the "business logic" goes in the scripts, and the "display logic" goes into the templates.
      But with that pattern, I honestly don't see the point of PHP over any other scripting language with strong template systems built on it.

      You're right. But with PHP (where textual content is easy due to the special-case <?php= $stuff ?> syntax), I get a turing-complete templating system out-of-the-box. It does come with an added discipline cost on my part, because the templating system is the same as the programming language.

      I'd hope that a better-designed framework—not necessarily more complex—would force people to think in a different way.

      Probably. But that's not going to stop so many people from using existing systems that work, even if they're not optimal, such as PHP (with warnings turned off entirely, using gpc_magic_quotes, and all of the other "stupid programmer" features enabled) or Visual Basic scripts embedded in Office documents. It's hard to create something that meets both criteria:

      • usable by people who do not identify themselves as programmers
      • designed to facilitate creation of maintainable programs
      ...simply because in many cases, they are at odds with each other. HTML pages are easy to create, because parsers are soooo forgiving. PHP is easy to hack, because it allows for the presence of subtle bugs. If you took away the honestly godawful hodgepodge implementation that is PHP, people would just come up with something else and make it equally easy for non-programmers (and thus a godawful hodgepodge from the perspective of us programmers).

      Now that I think about it more... the only real reasons why I still use PHP is because deployment is dirt simple and because I already know most the quirks and stumbling blocks that every programmer will eventually hit with it.

    12. Re:That's not why it's been criticized. by SanityInAnarchy · · Score: 1

      I don't see this as any different than Perl having built-in regular expressions or $_, or any shell using stdin/stdout as a value-passing mechanism.

      In Perl's case, you're somewhat right about regular expressions, but it's kind of hard to abuse them. Pretty much anything that deals with text could use regular expressions. For a better example, look at Perl formats, which were actually removed from the core language, but left as modules.

      Heck, we could do away entirely with printf() and just use fprintf(stdout, ...) for the C standard library.

      Two things with that:

      First, that's not special syntax, it's a function call.

      Second, again, it's a library. The standard library, but a library nonetheless. I don't have to include stdio.h.

      As to a language based around OpenGL/graphics primitives... the Alias|Wavefront OBJ file format is a declarative form of just that. It wouldn't suprise me to see someone use an embedded Lua interpreter to create a procedural "file format" for graphics primitives.

      Certainly, and there is a form of C meant for actually running on the video hardware -- as in, you write shaders with it.

      But a shader is just a shader, it's not going to become anything more than that. A somewhat-dynamic webpage could very quickly become a web app, and at that point, I'd much rather have a solid general-purpose language in it.

      You're right. But with PHP (where textual content is easy due to the special-case syntax), I get a turing-complete templating system out-of-the-box.

      Erm... I still don't really see the advantage. After all, if out-of-the-box-ness is important, may as well use rails. A few simple commands, and you have everything in place, including a templating engine.

      I don't necessarily think a templating engine should be Turing-complete, but that's moot anyway -- as I said, these other languages do have embedded versions of themselves now.

      Now that I think about it more... the only real reasons why I still use PHP is because deployment is dirt simple and because I already know most the quirks and stumbling blocks that every programmer will eventually hit with it.

      See, that one, I really can't blame you for. But were you to do it over, would you rather know the quirks of PHP, or of something else?

      Ah, well. Nobody's gotten it right yet, anyway.

      --
      Don't thank God, thank a doctor!
    13. Re:That's not why it's been criticized. by smellotron · · Score: 1

      But a shader is just a shader, it's not going to become anything more than that.

      The recent trend has been to attempt to abuse shaders as much as possible... anything that benefits from shader ops running as parallel math co-processors (textures are arrays, shaders are map() or reduce() operations). It's an absolutely awful programming environment!

      But were you to do it over, would you rather know the quirks of PHP, or of something else?

      I don't know... I'd probably suck it up and learn Perl better. My current opinion is that reading sloppy perl is about two ticks better than getting whipped in the face with a leather belt... and I haven't seen very much clean Perl.

  17. Be Aware, PHP behind !!! by YuuShiSann · · Score: 2, Insightful

    I've used Smalltalk, C++, Java, Python etc. 1st time experience using PHP in real OO dev with phpUnit. I have enough pain with PHP language defects that remind me with the pain with C++. This is my wisdom, use PHP carefully like C++ as there are a lot of language traps behind the close door. The biggest defects is the array comparison. I think PHP is doing copy-on-write behind the scene; but the lacking of way to compare the object identity is a real pain. Both '==' & '===' are fooling. There are still a lot defects I've discovered. I think I have enough content to write an anit-pattern for PHP.

    1. Re:Be Aware, PHP behind !!! by nuzak · · Score: 4, Interesting

      I remember the the discussion on IRC that lead to the creation of the === operator. The designers of the language (back when they hung out on IRC) actually did not comprehend the concept of "object identity". I had to eventually resort to calling it a pointer compare, at which time I was told "PHP isn't C, it doesn't have pointers". That was pretty much the end of PHP for me.

      --
      Done with slashdot, done with nerds, getting a life.
    2. Re:Be Aware, PHP behind !!! by YuuShiSann · · Score: 1

      Thank you for telling this. In fact, I think the PHP copy semantic makes the object identity impossible. Without the objectId, you have to consider all objects as copies. In order to do object reference, we have to use Value Holder design pattern; however, it is too much for a simple web application. If I have a choice, I will not use PHP.

  18. Publisher web site by Anonymous Coward · · Score: 3, Informative

    Maybe a ./ editor can fix the link in the article for the rest of us ;-)

    The publisher link in the article should have been: http://www.manning.com/reiersol/

    Thanks in advance

    1. Re:Publisher web site by jalsk · · Score: 1

      Hmm... not sure who a ./ editor is...

  19. php's ok for non-OOP applications by pak9rabid · · Score: 1

    For something that doesn't require the complexity of OOP, I think PHP does a decent job of getting what u need done quickly...assuming you're not a tard of a programmer. I like it's syntax (I come from a C background), as compared to Perl (which resembes the illegitimate child of C and LISP with down syndrome). Not to mention the documentation via www.php.net is nice.

    1. Re:php's ok for non-OOP applications by famebait · · Score: 1

      For something that doesn't require the complexity of OOP

      OOP is not complex (although some languages that use it are), when
      implemented well it makes life simpler.

      Once you really get OOP under your skin, programming without it
      feels like a work-around, even for tiny projects.

      --
      sudo ergo sum
  20. Re:Looks like a great book if you're stuck with PH by Dan+Posluns · · Score: 1
    I love PHP for prototyping ideas, and the html-integration as well as the hard-to-beat completeness of the supporting libraries makes it great for writing quick scripts where I want a webbish-GUI. Everything exposed in the global namespace? No problem when all I want to do is some quick processing of an image or some other data.

    But that very nature lends itself to a paradigm that makes it far too easy to eschew software engineering principals. So you reap what you sow.

    Yes, you can do OOP in PHP. But on large projects - and especially multi-programmer projects - you or somebody on your team is probably gonna wind up succumbing to doing things the way the language makes easy.

    Now excuse me while I go write some sparkly, gorgeous Python code.

    Dan.

  21. Perl and rationality by Anonymous Coward · · Score: 0

    How can I consider a language that was created by an irrational person?

    1. Re:Perl and rationality by Hucko · · Score: 1

      One wonders how you communicate at all, as very few languages can purport to be rational... especially the one in which you posted.

      --
      Semi-automatic amateur armchair Australian philosopher; conjecture ready at any moment...
  22. Grammar...where is the QC? by Gaston · · Score: 0, Troll

    "But with the released of version 5, PHP introduced..."

    Any reasonable 10 year old word processor grammar check would catch this. Or Slashdot can just hire a 10 year old.

  23. Want Real OOP Evidence by Tablizer · · Score: 2, Insightful

    a robust object model, and made it easier for its proponents to create well-architected Web sites and applications.

    I've never seen good examples of OOP making websites or typical business clearly better. Any bad non-OO coding presented was merely poor knowledge of procedural, bad specific languages, or lack of knowledge about good relational techniques. I challenge anybody to clearly demonstrate OOP being better for the mentioned domains.

    I've found flaws with the OO books out there. For one, they assume unrealistic change patterns to artificially boost OO. And please no anecdotes; for those are not dissectable. If OO fits your own personal psychology better, that's fine, but I don't wear your head.

    1. Re:Want Real OOP Evidence by bishiraver · · Score: 1

      1) maintainability
      2) understandability
      3) code reusability
      4) loosely coupled code
      5) modular code

      If you don't understand how these can be helpful in business and heavy web applications, you've probably never worked on one with a team before..

    2. Re:Want Real OOP Evidence by mlwmohawk · · Score: 1

      I have to laugh. I was just having a conversation with a Java/Swing guy and everything you list is precisely what what's missing from the modern "OO" environment.

      Yes, I agree, as a concept, well written OO can provide those things that you mention:

      1) maintainability
      2) understandability
      3) code reusability
      4) loosely coupled code
      5) modular code


      Then again, *any* well written code provides those things. What we see, however, is ever growing heaps of interdependent class libraries who's periodic API deltas cause huge amounts of "re-integration" every time a single component is upgraded.

      I would say, if you think OO is some magic bullet, spend a week on Java Swing.

    3. Re:Want Real OOP Evidence by __aanonl8035 · · Score: 1

      I just want to comment on

      2) understandability

      This actually is a result of a self fulfilling prophecy of sorts. No one, to my knowledge, has ever demonstrated that OO was inherently more understandable than other methodologies. But I do not dispute your point in the context of the other points you bring up, for in a sense, it is true.

      The reason...

      It appears to me that colleges all bought into OO. And so they churned out a vast number of graduates who all spoke the OO language. And so if you hire people, you are more likely to find someone who does things in OO. Or the majority of books published (like the one in the review) concentrate on OO.

      My personal opinion (not to be construed as an attack against your post) is that OO on a basic level is more difficult to understand than a procedural equivalent. I base this on anecdotal evidence of all the programming teams I have worked on over the years. (~20 other coworkers over 10 years) and having to explain the nuances of various systems in OO.

    4. Re:Want Real OOP Evidence by Tablizer · · Score: 1

      Those are the common OO buzz-claims, but I've never seen realistic code that demonstrated such actually taking place. The shape, animal, and device driver examples don't match the patterns I see in the real world and realistic OO code is messier than the alternatives. Note that "reusability" has fallen out of favor as a primary claim point among OO proponents. And "coupling" is difficult to define and measure fairly.

    5. Re:Want Real OOP Evidence by Dutch+Gun · · Score: 1

      OO on a basic level is more difficult to understand than a procedural equivalent That's probably true. But a nail gun is also more complex / difficult to understand than a hammer. The reason it's chosen as the tool of choice by professional carpenters is that it's much more powerful.

      OOP does seem to be a double-edged sword, though. While well-written object-oriented code can be substantially easier to read and understand than well-written procedural code, badly written OOP code can be harder to understand and more complex than badly-written procedural code. So no, it's not exactly a panacea. But like all powerful tools, it really depends on the skill of the person using it.
      --
      Irony: Agile development has too much intertia to be abandoned now.
    6. Re:Want Real OOP Evidence by Tablizer · · Score: 1

      While well-written object-oriented code can be substantially easier to read and understand than well-written procedural code,

      Please show me a single example in the domains mentioned.

    7. Re:Want Real OOP Evidence by smellotron · · Score: 1

      And "coupling" is difficult to define and measure fairly.

      The most natural definition of "coupling" I've seen is to imagine the set of all variables in a program as nodes in a graph. Any time two variables are referenced in the same function, there is an edge between those two variables. What you'll end up with in many cases is that sets of variables tend to get used together, and the whole graph looks like a lot of small clusters. A good OO design captures that clustering, so the end result is that within a single object many member variables get used in tandem, but between objects there is relatively little sharing. This applies to well-written C code, as well (sockets and pthreads are examples of OO designs implemented in procedural languages).

      That may not be a fair measurement, but it's the best that I've seen. All it's really doing is putting up artificial walls between different parts (or layers) of a piece of software, so it's easy for a human to consume one chunk at a time. Of course, I'd argue that's what most of software development is about - implementing algorithms within the limitations of the human attention span (which is much smaller than a Turing machine).

    8. Re:Want Real OOP Evidence by smellotron · · Score: 1

      Please show me a single example in the domains mentioned.

      You may disagree and vomit on me for saying this, but how about the OpenGL API? Even though it's all in C, it seems to me that it has a mixture of procedural and OO calls:

      • Texture, lighting, GLU quadrics, etc. all have sets of functions operate on objects. You can show an average developer a set of all texture-related functions and the concept is easy to grasp because the scope is very clear and limited.
      • Rendering operations affect the "current state", and generally aren't treated as acting on objects. You just select shape types and draw points until you're done. You can show someone the set of all functions available for rendering, and IMHO it's more daunting because there's no concept of scope. As soon as you wrap some direct rendering calls into a glDrawList, the notion of object scope comes into play again, and all of the rendering commands can be encapsulated into a single draw list.

      I suppose I've cheated a bit... You asked for a demonstration of OO/procedural code, but my example is about an API. I conflate the two in my mind, though, because in my opinion, any well-written code is that way because of the internal interfaces and scoping constructs, whether they are procedural or OO.

    9. Re:Want Real OOP Evidence by Tablizer · · Score: 1

      A good OO design captures that clustering, so the end result is that within a single object many member variables get used in tandem, but between objects there is relatively little sharing. This applies to well-written C code, as well (sockets and pthreads are examples of OO designs implemented in procedural languages).

      But OO tends to hard-couple stuff that should be soft-coupled in my opinion. We need a way to better manage how things can dynamically change their grouping/affiliation when needed. Set theory seems do that better than OOP does, and RDBMS is where set theory usually resides (because its readily available there.) One should not force groupings, but rather manage them better, especially as things grow more complex.

    10. Re:Want Real OOP Evidence by Tablizer · · Score: 1

      I'm not sure what you mean by the second bullet point. Perhaps an example would help. However, you are generally demonstrating "systems software", which is a domain that OOP does relatively well in and where the best OO examples come from. I just see it making a dull thud in the domains originally mentioned. Perhaps this is because in systems software, the entities are defined by engineers who strive to keep them fairly logical and clean, but in custom biz apps, the entities are defined by the whims of managers and marketers, and are thus messier and more interrelated.

    11. Re:Want Real OOP Evidence by Dutch+Gun · · Score: 1

      I think you're correct in a way, but I might disagree with your conclusion. If you need a more dynamic approach, then a better solution is to break the functionality up into smaller chunks, and build a framework that allows to you re-arrange those chunks with less effort. I suppose this starts moving toward generic programming a bit, but OOP is the mechanism by which you can do that.

      Honestly, I think the #1 problem I've seen with object-oriented programming is that people tend to create classes that are far too large and unwieldy. A giant, monolithic class is really very little different than a procedural API that passes around a single context structure to maintain state. And yes, those types of classes are VERY hard to break apart, but not really much more than a procedural equivalent. It takes a lot of experience to be able to effectively break apart functionality into smaller, logical components.

      But don't misunderstand... OOP is not some sort of magic bullet. It's not going to solve any problems automatically for you. Like you mentioned, changing requirements are always a challenge.

      --
      Irony: Agile development has too much intertia to be abandoned now.
    12. Re:Want Real OOP Evidence by Tablizer · · Score: 1

      Honestly, I think the #1 problem I've seen with object-oriented programming is that people tend to create classes that are far too large and unwieldy.

      And some have complained that creating bunches of small class creates a "dandruff soup" of classes. Maybe OO *can* make software engineering easier, but so far nobody has documented how to use it to do that (outside of systems software). Thus, what I see out of OOP with custom apps is inweildy messes.

      I think another problem is that people strive for The Ultimate Generic Framework, which is a nearly impossible goal. To handle every possible variation, it becomes a feature pack-rat such that even if the implementation is encapsulated well, the interface is so large and anwieldy itself that the gizmo is nearly useless; let alone the problem of adding features without breaking the gazillion existing features and the 50 apps that use it.

      I've instead have resorted to "helper" functions instead of frameworks. Helpers are smaller utilities that automate common idioms of the domain, but can be tossed or altered (copy and paste from another similar app) as needed without marrying the thing: easy come easy go. The pressure to build a generic one-size-fits-all framework thus is diminished. And, one can learn from experimentation.

      The utilities often communicate with each other via associative arrays or tables. This sort of violates OO-style encapsulation because the data is "naked", but this is a *good thing* because one can intercept the arrays for use with different utilities. Formal encapsulation makes mixing and matching more difficult. To match an ever-changing domain (business), you need ever-changing interfaces and relationships between components.

      (I agree that for medical and safety applications, this may not be appropriate. It's meant for budget-minded companies that want lots of features and fast turnaround without red tape.)

  24. Don't blame the language for your stupidity by i_ate_god · · Score: 1

    That error is a result of throwing an exception where it can't ever be caught. This is YOUR FAULT entirely and not PHP's fault, but nice try shifting blame and all that.

    function __destruct()
    {
    throw new Exception('Look at me, I'm a fucking moron');
    }

    Just because you can't build a tree house doesn't mean it's the fault of the hammer. Nice try shifting blame though, you really sound far more intelligent than me and my crass reply to your idiocy.

    --
    I'm god, but it's a bit of a drag really...
  25. PHP and the web by mlwmohawk · · Score: 4, Insightful

    PHP, or "Personal Home Page" to us old time users (Not PHP Hypertext Processor, as some revisionists would have to believe.) is a simple web scripting language first envisioned in the 90s for making simple web pages.

    For what it is, PHP is pretty good, a quick and dirty scripting language that, if used right, can make some pretty impressive applications.

    The real problem with PHP is the bickering and infighting little boys club that is the PHP development community. Over time they've learned a lot, but for the most part they believe they know everything and everyone else is wrong. Even though there are public forums, decisions are made on IRC chats. It is not as transparent or well functioning as groups like Apache, PostgreSQL, and others. A lot of petty crap goes on behind the scenes and a lot of people who would have been active contributors get pissed off and leave.

    I could go on with first hand and second hand stories and it is my opinion that it is this lack of professionalism that hinders PHP quality and adoption on an enterprise level.

    All that being said, PHP has a solid purpose in the web world. Java and .NET environments, and things like JSF or Swing are HUGELY complex and difficult to manage. With a continuum between simple HTML docs to HUGE applications, PHP sits in a very wide middle ground that it easy to manage and deploy.

    1. Re:PHP and the web by sneakyimp · · Score: 1

      WELL PUT!

      PHP is the shiznit. It's a got a huge collection of extremely useful native functions. Some of my favorite functions and primitives in 5.2:
      * json_encode
      * json_decode
      * file_get_contents
      * fgetcsv
      * preg_match
      * for...each

      These make it really easy to import data from text files, interface with JSON, etc. I know it's pretty noobish, but I also like the weak data typing. These things are the building blocks which make PHP so easy and expressive for new users. You don't waste time writing your own file parsing routines or casting variable types or searching for some library.

      I'd like to see a poll here at /. : WHAT IS THE ULTIMATE SERVER SCRIPTING LANGUAGE.

  26. Break backwards compatibility, fix PHP for good by Anonymous Coward · · Score: 1, Insightful

    As someone who's been using PHP for about 7 years (and someone who's gotten quite wealthy because of it), I have to say, among its many inadequacies, the insane inconsistencies PHP has with naming conventions makes me want to eat glass. I say with PHP 6.0 they should deliberately break backwards compatibility and go with one solid naming convention for methods and functions. I don't care if they go with functions_with_underscores or functionsInCamelCase, just as long as it's consistent.

    1. Re:Break backwards compatibility, fix PHP for good by LordLucless · · Score: 1

      They don't even need to break backwards compatibility - they've already got a truckload of aliases in there. Just create a new set of functions with a standard naming convetion, alias all the old names, and deprecate them. A couple of versions later when everyone's using the standards, then you can drop the aliases with little effect.

      --
      Just because you're paranoid doesn't mean there isn't an invisible demon about to eat your face
  27. PHP is a fine language by s2theg · · Score: 2, Insightful

    I chose to work with PHP due to its flexibility. Writing software by creating types is useful in certain places, but I have found that it tends to require more code to be written than is needed for most web applications. Many of the applications which I currently maintain have been written elegantly using basic GET and POST checking and a series simple of functions.

    1. Re:PHP is a fine language by potHead42 · · Score: 1

      Writing software by creating types is useful in certain places, but I have found that it tends to require more code to be written than is needed for most web applications. Umm... you know, there are other dynamically typed languages besides PHP...
  28. Are you sure you understand? by bigtrike · · Score: 2, Interesting

    My problem had nothing to do with destructors. There are other contexts where they can't be used. But of course you knew that, even though they're not really documented.

    function a() { new DateTime('2007-02-32'); }
    function b() { a(); }
    register_shutdown_function('b');

    And even then my complaint isn't that you can't do that, but that there is absolutely no way to track down the source of that error because unlike most other PHP errors, you're told it's on line 0 of Unknown.

  29. PHP Vs Python by wiseguy02 · · Score: 1

    Maybe this isn't the spot to post this, but I will anyway:). I've been looking into learning a good web developing program, I am wondering what most people prefer. I have been toying with PHP a little, but recently have been pointed in the direction of Python. After reading some of the comments in here I'm curious what are your thoughts?

    1. Re:PHP Vs Python by Serious+Callers+Only · · Score: 1

      Learn Python (or another scripting language like ruby or smalltalk), then PHP. Then you'll understand why people say PHP is ill-considered. It won't take you long to learn the basics of a couple of languages, and it's worth doing that just so that you can compare them. If you only learn one, you'll never know what's good and bad about it.

  30. don't forget one big subtle problem: php.ini by Anonymous Coward · · Score: 0

    You could spend all day listing the problems with PHP, but one that doesn't get mentioned nearly enough is:

    PHP.INI means there are thousands of variations of the language.

    See, I'm one of those crazy people who values predictability and precision in my software. For instance if my software assumes that a number is always less than 100, the database better fucking enforce that constraint, otherwise I consider it a bug in either the software or the database. Likewise, if my development machine has safe mode off, I want to ENFORCE that the deployment machine also has safe mode off, and so on.

    And having to make sure all the settings in PHP.ini are right when deploying software is simply ridiculous. Does it allow short tags? Is safe mode on? File uploads allowed? AUTO QUOTING BULLSHIT \' \' (what were they thinking)??? Session handling? Session timeouts?

    I have deployment scripts now that automatically verify all this BS (don't forget, you can change some settings in .htaccess and apache configs too, so don't just test from the command line), but I long for the day when PHP is just the same for everybody when it starts up, and settings must be changed *at run time* or in some automateable way.

    It amazes how little PHP programmers complain about this and other limitations of PHP. Either they are incompetent, or they have accepted a level of unpredictability in their software even higher than the programming community at large.

    1. Re:don't forget one big subtle problem: php.ini by SanityInAnarchy · · Score: 1

      PHP.INI means there are thousands of variations of the language.

      I don't see that as a problem. Or at least, the problem there is that those variations are in PHP.INI, which isn't exactly accessible to the application developer.

      Take Ruby -- as I've been re-learning Ruby for work, I've also had to learn Rake and Capistrano, both of which can be seen as mini-languages built on top of Ruby. This is a feature, not a bug -- plus, no one is forcing me to use Rake, even in a so-called Rake script.

      --
      Don't thank God, thank a doctor!
  31. Language Wars = Useless by Anonymous Coward · · Score: 0

    Good grief, not another pointless language A is better than language B discussion. Fact of the matter is, is that not one language exists that will work perfectly in all situations. Pick the right tool for you and for the job at hand. For dynamic web pages, PHP does a pretty damn good job (think about how many Java web apps could have easily have been done more efficiently in PHP??..don't lie), but you certainly wouldn't be building any desktop applications with PHP.

    And for the love of God, quit comparing interpreted scripting languages to languages like Java/C++...that doesn't work.

    1. Re:Language Wars = Useless by Tablizer · · Score: 1

      Fact of the matter is, is that not one language exists that will work perfectly in all situations.

      They will if they are Turing Complete.

  32. Excellent bathroom ..er... reading? by Anonymous Coward · · Score: 0

    "Several of the pages had light brown spots on them that were apparently part of the paper, and not a result of post-production staining."

    Good lord! Are you sure? Were the pages a bit wrinkled too?

  33. Why PHP sucks by Anonymous Coward · · Score: 0

    Taken from http://www.bitstorm.org/edwin/en/php/

    1. Bad recursion

    Recursion is the mechanism in which a function calls itself. This is a powerful feature which can make something complex something simple. An example of a function using recursion is quicksort. Unfortunately, PHP is not good at recursion. Zeev, one or the developers of PHP, says this: "PHP 4.0 (Zend) uses the stack for intensive data, rather than using the heap. That means that its tolerance recursive functions is significantly lower than that of other languages." See bug 1901. This is a poor excuse. Every programming language should provide good recursion support.

    2. Many PHP-modules are not thread safe

    A couple of years ago, Apache released version 2.0 of its web server. This version supports multithreaded mode, in which one piece of software can run multiple times simultaneously. The makers of PHP say that the core of PHP is thread safe, only the non-core modules often aren't. But nine out of ten times, you do want to use such a module in your PHP-script, making your script unsuitable for Apache's multithreaded mode. That's why The PHP Group doesn't recommend running PHP on Apache 2 in multithreaded mode. The bad multithreaded mode support of PHP is often seen as the reason Apache 2 still didn't catch on.

    3. PHP is crippled for commercial reasons

    The performance of PHP can be increased to 500% by using caching [benchmarks]. So why is caching not build into PHP? Because Zend, the maker of PHP is selling its own Zend Accelerator and of course, they don't want to cannibalize on there own commercial products.

    4. No namespaces

    Suppose someone creates a PHP-module that can read files. One of the functions in this module is called read. And someone else's module can read web pages and also contains a function read. Then it is impossible to use these modules together because PHP will not know which read function you want.

    An easy solution to this is namespaces. It was a suggested feature for PHP 5, but unfortunately it didn't make it. Now, without namespaces, every function has to be prefixed with the module name, to prevent name collisions. This leads to terrible long function names like xsl_xsltprocessor_transform_to_xml which makes code harder to write and read.

    5. Non-standard date format characters

    Many programmers are familiar with the date format characters known from UNIX and the C programming language. Other programming languages adopted this standard, but strangely enough, PHP has its own, completely incompatible date format characters. While in C, "%j" stands for the day of the year, in PHP this stands for the day of the month. To make things even more confusing: the function strftime and the date_format of Smarty, a PHP templating engine, do use the C/UNIX format characters.

    6. Confusing licenses

    You might think PHP is free and all PHP-modules in the manual are free too. Wrong. For example, if you want to generate a PDF-file from PHP you will find two modules in the manual: PDF or ClibPDF. But both come with commercial licenses. So for every module you use, you have to make sure you agree with its license.

    7. Inconsequent function naming convention

    Some function names consist of more than one word. There are three conventions for combining these words:

    1. Glued together: getnumberoffiles
    2. Separated with underscores: get_number_of_files
    3. Camel case: getNumberOfFiles

    Most Languages choose one of these variants. PHP uses all of them.

    For example, it you want to convert special characters to HTML entities, you use the function htmlentities (Words glued together). If you want to do the opposite, you use its little brother function html_entity_decode. For some reason the words are now separated by underscores. Why is this bad? You know there is a function named strpad. Or was it str_pad? Every time you hav

    1. Re:Why PHP sucks by Tablizer · · Score: 1

      Bad recursion

      Recursion is not used often enough to make a difference. If you use a lot of recursion, you'd probably prefer Lisp.

      Many PHP-modules are not thread safe

      It's not a common need unless you are doing something odd. If you put every pet feature into a language, it becomes a bloated mess.

      You might think PHP is free and all PHP-modules in the manual are free too. Wrong. For example, if you want to generate a PDF-file from PHP you will find two modules in the manual: PDF or ClibPDF. But both come with commercial licenses.

      If module-writers use a funny license, why are you blaming it on the language? I could make a module for say Perl and use any fricken license I want. If you don't want to use my library for that reason, then don't use it. You seem to be complaining about the existence of library choice.

      The most popular model for a framework is the MVC-model,

      Perhaps it is a personal preference, but I think MVC sucks and is driven by dogma instead of reason.

      No Unicode

      Never missed it. Maybe if I was a Swahili programmer, it would matter to me. But, I am not. One can use HTML escape codes for the rare occasions it is needed. In fact, unicode complicates things: you get funny characters that are not what they seem.

    2. Re:Why PHP sucks by LuckyStarr · · Score: 1

      Many PHP-modules are not thread safe

      It's not a common need unless you are doing something odd. If you put every pet feature into a language, it becomes a bloated mess.
      Like trying to use the more efficient threading model of Apache2 instead of the resource hogging forking one which I still have to use with PHP?
      --
      Meme of the day: I browse "Disable Sigs: Checked". So should you.
    3. Re:Why PHP sucks by Tablizer · · Score: 1

      You seem to be talking about the perspective of the web server, not about multi-tasking application code, correct?

    4. Re:Why PHP sucks by LuckyStarr · · Score: 1

      You seem to be talking about the perspective of the web server, not about multi-tasking application code, correct?
      Which does not matter. The standard PHP implementation does not support threading anyway, so using PHP in a threaded webserver is the only way to fall over not thread safe modules. And there a plenty of them.
      --
      Meme of the day: I browse "Disable Sigs: Checked". So should you.
  34. Why php is used by Anonymous Coward · · Score: 0

    The reason why people use php is because of the huge list of built-in functions. I would prefer to use ruby (I love the way it handles), but I can't be bothered to spend 3 months hunting down and/or coding every string and numeric function that ruby doesn't have built-in. I've seen other people's ruby's projects, and they're not pretty to look at -- thousands upon thousands of lines of code extending String and Fixnum just to provide basic functionality that is provided for you with no hassle in php.

    I refuse to touch other people's php code unless my job depends on dealing with it. Most people who code php don't even realize that $var = $_GET['foo']; can return an array. Let alone the fact that people still write code for fucking 4.x, which just pisses me right off. Yes, everyone programs differently, and every programmer thinks their code is written better/cleaner/more secure than everyone else's. But seriously, there are far too many php coders who learn only as much as they have to in order to "get the job done".

    I think my biggest peeve with php is the fact that var_dump("1e1" == "10"); evaluates as true (for some truly fucked up reason, comparing 2 "numerical" strings converts both operands to integers).

    1. Re:Why php is used by Tablizer · · Score: 1

      I think my biggest peeve with php is the fact that var_dump("1e1" == "10"); evaluates as true (for some truly fucked up reason, comparing 2 "numerical" strings converts both operands to integers).

      That's living with dynamic typing. Personally, I think comparison operators in such langs need to be tossed for something more powerful, but that's a topic for another day.

    2. Re:Why php is used by famebait · · Score: 1

      The reason why people use php is because of the huge list of built-in functions.

      There are some unusual ones that are nice to have, but most are in fact equally well covered in other languages' standard classes, and would have been better to support as class methods than global functions.

      The main reason _I_ sometimes use it is that I _know_ I will be able to deploy it at whatever ISP I might decide to use. And that there is extremely little overhead with starting to toy with a new project compared to many server-side platforms.

      5.x _is_ a huge improvement, to the extent that you can now actually use it to do real work even if you know how to design applications. But it still feels like a pile-of-hacks language-wannabe.

      --
      sudo ergo sum
    3. Re:Why php is used by rgagnon · · Score: 1

      if someone would bother to read the documentation for comparators.... You would know that "==" is supposed to do that. Use "===" if you also want the datatype included in the comparison. var_dump("1e1" === "10") revealse the expected "false"

  35. Fixed it for ya by Anonymous Coward · · Score: 0

    echo foo(1);

    Which, in reality will work better in the second place. :-O

  36. Wrong question by Anonymous Coward · · Score: 0

    For the love of god, please don't learn "a language". There are a million dorks out there who know a language or two, but can't program worth shit. Don't get hung up on "the web", either.

    First, learn to program.

    1. Re:Wrong question by mysticgoat · · Score: 0

      For the love of god, please don't learn "a language".

      Someone mod parent up. At last, a reasoned answer.

      Begin with the principles of good procedural programming: well-factored modules, structured programming practices, pseudocode, blackbox functions, private vs public data, reasonable naming schemes, etc. Learn how to do progressive refinement, top-down analysis, and bottom-up coding (where appropriate), factoring, refactoring, and planning for revisions. There are always revisions. You will also learn how to stack several open reference books on your desk and keep several browser tabs open to different online resources, and be able to quickly juggle through these to find out the exact syntax of foo(bar) when you need it. Learn self-discipline by keeping on task on the procedural stuff and avoiding OOP, event-driven paradigms, re-entrant and recursive processes, self-modifying code, and so on, no matter how enticing their give-me-a-whirl come-ons are. Save that stuff for later, after you've got a solid grounding in basic procedural theory and practice. You can become proficient in procedural programming using PHP and Javascript. Doing so while limiting yourself to only the parts of these languages that are needed for structured programming will help develop the discipline of mind that makes more advanced work possible. Call this the first thread.

      Concurrent with the first thread, learn two declarative programming languages: HTML and CSS. Start by hand-coding static web pages, then braid this second thread of learning into the first thread by writing PHP scripts that compose HTML and CSS on the fly. Pay attention to the profound differences between procedural programming and declarative programming. Mess around some with DHTML. Get your mind used to jumping quickly from one mental framework to another: server to client; PHP that dynamically constructs Javascript that dynamically alters HTML, etc. And don't neglect exploring the arguments about HTML/CSS standardization and usage that have been bubbling and frothing on the web for a dozen years, with no let up in sight. Those battles are going to be a part of our landscape for probably another decade; if you are going to be involved in web development, you need to become familiar with the politics.

      By the time you are comfortable with the subjects of the first two threads, you will have a broader skill set than many people who have been "doing web site design" for several years. You can build a portfolio that will get you a job. Make something nice for your church or civic club.

      Third thread: Learn more about data structures, both persistent and volatile. Learn SQL and basic relational database theory, with emphasis on using the normal forms as an analytical tool. Explore serialization techniques as an alternate mode of persistence. Get comfortable with arrays, associative arrays, and complex data structures. For the sake of your sanity, delay the start of this until after you are fairly comfortable with the subjects of the first two threads.

      All the above can be done on the AMP stack with a standards compliant browser handling the I/O. XAMPP and Firefox are good tools for this for local development on Windows machines. By physically disconnecting from the internet before launching XAMPP, you can be sure from the very beginning of your studies that you are not compromising your machine by unwittingly opening up security holes.

      Woven through all the above, learn two more languages. Perl, because when you can write self-documenting code in Perl that another programmer will understand on his first reading, you will know that you have advanced well beyond the novice programmer stage. No other language is as good as Perl for this, because, like English, Perl allows you to write both pure garbage and Shakespearian quality code. Perl gives you more than enough rope to hang yourself, and makes the very nasty assumption that you actually know what you are doing. So if you can write good code in Perl, t

  37. misleading heading... by ynohoo · · Score: 1

    "Despite being perhaps the most popular Web language in use, PHP has for much of its history been criticized for not offering the full restrictions of object-oriented programming"

    There, fixed that for you.
    kthxbye!

  38. The only good PHP5 book I've read by mcalwell · · Score: 1

    This, along with the generic O'Reilly PHP reference book, is the only useful PHP book I've ever read. I would recommend it.

  39. Maybe I'm just lazy.... by ChronoFish · · Score: 2, Interesting

    Maybe I'm just lazy,

    I'll accept that. I grew up programming in Pascal and BASIC, turned to C/C++ and loved it through college and my first 8 years of my software development career, dabbled in Java for a year - and then found PHP. For the last 5 years I have been programming in the language of my choice - PHP - and loving it. It's quick, it's easy, it's powerful. I find it just as easy to write a web server (Yes you can write a web server in PHP - the networking and forking functions are great - I've even successfully written apps that use COM to manipulate Excel) as it is to write a web app.

    Maybe my past experience allows me to write structured code without having the language force me to write structured code. Maybe my ideas of OO is backwards - I look at data as "black data" and functions "just handle it" rather than forcing the programmer to know what the data is in a strictly typed language (C++/Java).

    If you *want* to handle memory allocation - yeah - C/C++ is for you. But when you do that you're solving programming problems. You're not solving the customers problems. When you're a software developer you should be developing solutions for your customers - not solutions for the language you're developing in.

    Are there issues with PHP? Of course. Is it THE language to use? Only if you know it and it fits the problem you're trying to solve.

    -CF

    1. Re:Maybe I'm just lazy.... by SanityInAnarchy · · Score: 0, Troll

      All of the reasons you've just given are all the more reason for you to learn a real dynamic scripting language. Try Perl, Python, or Ruby, though not necessarily in that order. Even Javascript.

      It's not just that I hate PHP, although I do. It's that the only thing PHP has that these other languages don't is the <?php ... ?> syntax, and all of them can do that already, to some extent.

      Ruby has deep, pervasive OO, not just tacked on; pervasive patterns around anonymous callbacks (each, select, insert, and friends); and beautiful syntax.

      Perl has a sweet code library (CPAN) such that most programs I write end up being less than 100 lines of code. Anything you want to do has probably already been done in CPAN.

      Python is simple. Simple to pick up, learn, and use, and the strict syntax forces everything to be somewhat understandable. Plus, you can fly.

      PHP has tacked-on OO, tons of code in web apps (pretty horrible code, too) but not much in libraries (so not easy to tie together), ass-ugly syntax, and, in general, no redeeming qualities. Except that you already know it, and it embeds in webpages.

      Well, except that every one of the other languages I mentioned have plenty of templating systems for them already. You can certainly embed Perl and Python in a webpage (embperl, rhtml). So I guess that leaves PHP with "you already know it" and "a bunch of web apps are written in it". Not a very compelling argument, unless you happen to be maintaining one of said webapps.

      --
      Don't thank God, thank a doctor!
    2. Re:Maybe I'm just lazy.... by smellotron · · Score: 1

      If you *want* to handle memory allocation - yeah - C/C++ is for you. But when you do that you're solving programming problems. You're not solving the customers problems.

      Rhetorical question: What if the customer's problems are that the previous programmer solved everything with scripting languages, and the runtime performance is abysmal?

  40. Moar like... by trekie9001 · · Score: 1

    PHP in action, moar like PHP inaction, amirite?

  41. Re:Looks like a great book if you're stuck with PH by jo42 · · Score: 1

    Remember folks, the acronym for PHP Object Oriented Programming is POOP.