Slashdot Mirror


PHP 5.4 Released

mikejuk writes "PHP 5.4 has been released, along with a new version of Zend Framework. It has a number of optimizations that make it faster and smaller (early estimates say 10-20% faster), a built-in webserver for testing purposes, and features that had been destined for PHP 6.0. The big addition from the now-crashed PHP 6.0 project is Traits, which are sort of a cross between a class and an interface, bringing some of the advantages of multiple inheritance to PHP. The full changelog and download page are both available."

40 of 209 comments (clear)

  1. That's all we need ... by Barbara,+not+Barbie · · Score: 4, Insightful

    a cross between a class and an interface,

    ... having php adopt a bad idea from Java and making it worse? Wouldn't we be better off actually having static typing instead?

    --
    Let's call it what it is, Anti-Social Media.
    1. Re:That's all we need ... by Daniel+Dvorkin · · Score: 4, Insightful

      Java interfaces are essentially a fancy form of documentation. Traits sound like they provide actual functionality.

      As for static typing ... oh, never mind. If you prefer static typing, by all means, use a language that has it. Also bear in mind that static typing != strong typing; a lot of people who complain about the lack of the first really seem to be talking about the second.

      --
      The correlation between ignorance of statistics and using "correlation is not causation" as an argument is close to 1.
    2. Re:That's all we need ... by Yvan256 · · Score: 4, Funny

      No idea, but a sheet of Bounce would probably solve that problem.

    3. Re:That's all we need ... by Daniel+Dvorkin · · Score: 2

      They are also a contract

      And, IMO, a contract is a fancy form of documentation. If you can't implement any functionality in it, it doesn't do anything that a careful check of the program against the design specs can't also accomplish. I'm not saying interfaces are useless, but I wish people would stop saying "we don't need multiple inheritance, we've got interfaces!" when they don't do anywhere near the same thing.

      --
      The correlation between ignorance of statistics and using "correlation is not causation" as an argument is close to 1.
    4. Re:That's all we need ... by msobkow · · Score: 2

      Interfaces are a method contract, not "fancy...documentation."

      If you think interfaces are "just" documentation, you don't know SHIT about OO programming. Sorry dude, but your perspective is like saying that C/C++/C#/Java are "just" big macro assemblers because everything eventually runs on a CPU.

      --
      I do not fail; I succeed at finding out what does not work.
    5. Re:That's all we need ... by rev0lt · · Score: 2

      Multiple inheritance isn't a Java concept. It's a OO concept, older than java itself. Also, PHP isn't a OO development language, but a scripting language that supports OO constructs, and the latest releases have been focusing hard on modern OO funcionality. If you don't like a given feature, don't use it. Try do something in java that doesn't involve instantiation of an object.

  2. Re:advantages of multiple inheritance by Anonymous Coward · · Score: 5, Insightful

    GOTO is perfectly fine in some situations. Using a technique badly doesn't make the technique bad itself. It's just stupid users.

  3. Re:advantages of multiple inheritance by Anonymous Coward · · Score: 2, Informative

    Difficult to write assembly without "goto"

  4. Re:advantages of multiple inheritance by bieber · · Score: 4, Interesting

    Multiple inheritance is supported in some form or another in just about every OO language in existence. It's just that most prefer to restrict multiply-inherited traits to methods and call them "interfaces" instead of "base classes." IMO, that's entirely unnecessary. If I want an "interface" in C++, then I write a pure abstract class without any member variables and use it the same way I'd use an interface in Java. If I want true multiple inheritance in Java, I'm just out of luck. MI can be used in some very nasty ways, but if you tried to remove each and every feature that a programmer could possibly misuse from a language you'd pretty quickly find yourself with an insanely verbose toy language that no experienced developer would ever want to touch.

  5. Re:advantages of multiple inheritance by Daniel+Dvorkin · · Score: 2, Informative

    Like every other tool, multiple inheritance can be used or abused. It may be one of those tools which is actually more prone to abuse than to proper use, but that doesn't mean it can't be done right.

    For a specific example, I used to work on a database application stack which had a bunch of classes for database entities (People and Companies, say) each inheriting from a DBEntity class; and other classes, inheriting from the database-facing classes, to format those entities for display (DisplayPeople, DisplayCompanies, etc.) The display classes each had to inherit from the database-facing classes, and each had its own particular display needs, but there were also, unsurprsingly, a lot of display functions in common. It would have been very useful to be able to define a DisplayEntity class from which each of the display classes could have inherited, using the common methods when applicable and defining their own methods when needed.

    --
    The correlation between ignorance of statistics and using "correlation is not causation" as an argument is close to 1.
  6. Saying "PHP 5.4 Released" isn't that meaningful... by bogaboga · · Score: 3, Interesting

    Telling us readers how it (the new PHP) measures up to the competition would have been better and more informative.

    So, let me bite: How does this new release measure up to the competition?

  7. Oh good Lord by PCM2 · · Score: 4, Funny

    What synchronicity! Just the other day I was thinking about the beautiful and elegant poetry that is PHP's syntax and standard library, and I was saying to myself, "You know... if there's one thing PHP needs, it's multiple inheritance."

    --
    Breakfast served all day!
    1. Re:Oh good Lord by CastrTroy · · Score: 3, Insightful

      I don't even know why they added object oriented features in the first place. It's really hard to bolt something like Object Oriented features on to language that never had them. Not to mention that having half the standard library in OO and half in procedural just makes everything an even bigger mess. PHP would probably be a lot cleaner and more palatable had they never tried to add objects in the first place.

      --

      Anthropic principle: We see the universe the way it is because if it were different we would not be here to see it.
    2. Re:Oh good Lord by hcs_$reboot · · Score: 2

      Don't be too harsh about PHP. It's a rough language that allows almost anybody to write rough programs that eventually give rough results. A democratic language...

      --
      Slashdot, fix the reply notifications... You won't get away with it...
  8. PHP security by lanner · · Score: 2

    PHP has always been a security nightmare. Can anyone speak about security issues, enhancements, etc, that us sysadmins should know about?

    1. Re:PHP security by CastrTroy · · Score: 4, Informative

      PHP has had some security issues, but they can largely be avoid. First, always use parameterized queries (prepared statements) using PDO or MySQLi. Register Globals, which was a big problem in the past has been removed in 5.4. Most of the security problems I'm aware of can be summed up in those two things. I think the reason it has such a bad reputation is that it has so many newbie developers on it, and because there are a lot of bad tutorials out there (possibly written by newbies) that show bad practices, such as not using parameterized queries.

      --

      Anthropic principle: We see the universe the way it is because if it were different we would not be here to see it.
    2. Re:PHP security by Billly+Gates · · Score: 4, Funny

      Here is my code from my login page in php 4 that is super secure

      $query_login="select * FROM user";
      $result_login = mysql_query($query_login) or die("Your passwrod is might be bad I think"); //$login_check = mysql_num_rows($result_login);
      while($row=mysql_fetch_array($result_login))
      {
      $username=$row["username"];
      if ($username==$username1)
      {
      echo "";
      echo "window.location.href='login_error.php?rec=qq';";
      echo "";
      exit;
      }
      }

    3. Re:PHP security by ProzacPatient · · Score: 2

      Dear god I hope you're not serious

  9. Re:Saying "PHP 5.4 Released" isn't that meaningful by Anonymous Coward · · Score: 4, Funny

    well, it's PHP. And the competition is not PHP. So the competition wins.

  10. It's better than Ruby's "best practices". by Anonymous Coward · · Score: 5, Insightful

    The people who scream the loudest about how multiple inheritance or gotos are bad are the ones who also scream the loudest about "best practices", but in reality write some of the shittiest code there is.

    Just look at Java and C#. The worst Java and C# developers are those who go on and on about design patterns. Then instead of writing software that solves real problems, they spend months and years putting together frameworks and obtuse architectures that are damn near impossible to use in practice.

    Then there are the Ruby users. Basically everything they advocate is wrong. Maybe it lets you crank out yet another blog engine quickly, but what they propose falls apart completely for any moderately complex application. All it takes is debugging one problem caused by monkeypatching, and you'll immediately see how stupid their ideas are.

    JavaScript "programmers" are the worst. Their language is so fucked up, but most of them are so ignorant that they can't see this for themselves. I mean, they didn't even manage to get equality comparisons implemented in a sensible manner! Yes, very core functionality like that is broken.

    PHP has traditionally been just slightly better than JavaScript, in terms of developer stupidity, but at least they're making a small degree of progress in the right direction. We can't say the same for Ruby, though. In fact, we rarely hear about Ruby these days. The hype surrounding it sure has died down lately. This isn't completely unexpected. Consistent failures, like most sizable Ruby projects tend to be, can quickly kill even the loudest hype.

    1. Re:It's better than Ruby's "best practices". by datavirtue · · Score: 2

      I took one look at Ruby and that was it. I was left in complete shock as to why it had any hype at all.

      --
      I object to power without constructive purpose. --Spock
    2. Re:It's better than Ruby's "best practices". by MisterMidi · · Score: 3, Insightful

      Insightful my ass. The people who scream the loudest how fucked up some programming languages and how stupid their users are, are actually the worst.

      Sane programmers however, just use what's best for the job. For example, what other programming language would you suggest for enhancing a webpage? VBScript? Or just throw in a Java applet like in the nineties?

      If you think the equality comparisons of JavaScript are fucked up, I think you don't understand loose typing. If they don't do what you want, it's because you don't use them properly.

  11. Re:advantages of multiple inheritance by CastrTroy · · Score: 2

    Many languages provide fancy syntactic sugar type gotos so that developers can only make safe gotos. Some of these include things like "break" to exit a loop, or other commands like "exit for". As far as I'm concerned, Try/Catch is just fancy syntactic sugar for the old VB "On Error GoTo". Very much agree with you. There's nothing wrong with GoTo provided you use it right. Not having GoTo doesn't make terrible developers all of a sudden stop making crappy code.

    --

    Anthropic principle: We see the universe the way it is because if it were different we would not be here to see it.
  12. Re:advantages of multiple inheritance by petsounds · · Score: 2

    Taking away options in the language can make the outcome better. For instance, you *have* to strongly type in Java, and you *have* to put everything in classes. Surely its safe to say that Java tends to be more modular by default.

    This is sort of like saying democracy in the United States is better because the Constitutional Convention decided an Electoral College would help keep the masses in check. Speaking as a proponent of strong typing, I reject languages that force behavior on programmers. A good language *encourages* good behavior through elegance, pragmatism, and tangible benefit. A bad language creates unnecessary rules because the creators of the language think they know better than the users.

  13. how about some new template features? by GabboFlabbo · · Score: 2

    It'd be really nice if PHP would add some nice template features that Smarty / Twig have. (elseforeach, simple echo htmlentities construct ?)

    The developers of PHP are so focused on becoming a real language that they've forgotten what PHP is all about: templating! There's no real focus on adding template features (ok... I don't have to type array now...).

  14. Re:Saying "PHP 5.4 Released" isn't that meaningful by Anonymous Coward · · Score: 2, Insightful

    You base your criticism of a platform (not a language) on its name? Seems pretty arbitrary.

    On top of that, the old platform was just called COM (no dot).

    For what it's worth, I've used pretty much all the well-known languages out there (OO languages, functional ones, dynamic ones) and I have to say that the .NET framework and C# are pretty damn good. In particular, the C# language designers are really good at incorporating the good ideas from other languages but keeping the syntax from spiraling out of control (a la C++).

    Not that this opinion will garner much praise on slashdot.

    CAPTCHA: informed

  15. Re:PHP 6 crashed by wimg · · Score: 2

    Almost everything planned for PHP 6 is in 5.4, except for full unicode support, which was slowing down the entire language too much.

  16. Scan your code, folks by wimg · · Score: 5, Insightful

    If you want to get your code compatible, a start is to scan it automatically : https://github.com/wimg/PHPCompatibility - just released for 5.4 as well :-)

  17. Traits are cool by greywire · · Score: 2

    I've been waiting for traits in php (and thus php 5.4 when they finally decided to put traits into it) for some time now.

    Think of traits not as really an extension to the object oriented features (alternative to multiple inheritance..) but as a kind of language assisted cut and paste with conflict resolution.

    Because that's what it is. Traits are "flattened" at run time. Their methods become methods of the class where the trait is used, and work exactly like they were defined there to begin with. If there is a collision in the naming, you can specifically resolve that with language syntax.

    --
    -- Senior Software Engineer, Attorney appearance services, locallawyerapp.com.
  18. Re:advantages of multiple inheritance by Barbara,+not+Barbie · · Score: 3, Insightful
    Gotos are great. Look at your switch statement. See those case labels - they're the targets for the computed goto. Or do you not use switch statements?

    There's absolutely nothing wrong with goto. Just people who abused it and it got a bad reputation.

    --
    Let's call it what it is, Anti-Social Media.
  19. I'm not sure OO is a good idea for web development by walterbyrd · · Score: 2

    But that's just me.

  20. Re:advantages of multiple inheritance by siride · · Score: 2

    Only if you are using an assembly language that lets you directly modify the program counter with normal arithmetic instructions. x86 does not let you do this. You must use one of the jmp family of instructions (essentially goto), or call/int/ret/iret (and related).

  21. Re:advantages of multiple inheritance by shutdown+-p+now · · Score: 2

    I have yet to see an example where MI is the best solution in a real e.g. Java program.

    Generally speaking, public inheritance represents a "can-substitute-for" relationship (per Liskov substition principle). So whenever you have some A that can substitute for both B and C, you have multiple inheritance.

    In Java in particular, every time you implement an interface, you use multiple inheritance. That's plenty of examples right there in java.lang.*.

    You're going to say that interfaces are limited. Sure they are - you can't have fields, and methods can't have bodies. The second restriction is actually going away in Java 8 with "defender methods" - basically, the ability to provide default implementations for interface methods. Why is it useful? Well, you often have rich interfaces, such as e.g. collections, where a lot of members are going to be implemented the same way for all or at least most implementations, usually in terms of other members - e.g think about java.util.List#contains, which is normally implemented in terms of a simple loop. The way things are now, all implementations have to repeat themselves. In Java 8, it'll get a default standard implementation right there in List - so you get it for free when you implement it.

    Inheritance of fields is more questionable, mainly because you're forced to make a choice of how do deal with duplicate fields coming from "diamonds" in inheritance hierarchy. That's probably why it's used very rarely in C++, even though it's technically supported.

  22. Why "use" instead of "uses"? by Phantasmagoria · · Score: 2

    GRRR. "extends" was for inheritance, "implements" was for interfaces, so why wasn't "uses" chosen for traits, instead of "use"?
     

    --
    Loban Amaan Rahman ==> Anagram of ==> Aha! An Abnormal Man!
    1. Re:Why "use" instead of "uses"? by nyctopterus · · Score: 2

      Because this is PHP, man! Home of mysql_real_escape_string()!

    2. Re:Why "use" instead of "uses"? by tomhath · · Score: 2

      Because it's really more like "import".

  23. Re:advantages of multiple inheritance by msobkow · · Score: 2

    Multiple interface inheritance is necessary in order to specify a proper object model, but C++ is the only language I've ever used that supports multiple inheritance of methods and attributes as well as interface signatures.

    Certainly I find it far, far easier to code a system with C++ than with Java or C#. Both Java and C# require that you copy-paste-edit code between implementations of the interfaces, which results in a lot of code duplication and is more prone to error than the C++ approach. (Not to mention being in direct contradiction with the whole concept of code re-use.)

    Still, I do understand why it's difficult to work with C++. It's a true chainsaw of a language in the hands of an expert, with the resulting risk of slicing your own limbs off if you're not careful or don't know what you're doing.

    But unlike some, I don't blame a flexible language for letting programmers hang themselves. I come from the era of bits bytes and machine code, so while I understand and take advantage of the newer languages, I have no fear of dropping down to the nuts and bolts for performance, and I have an intimate knowledge of how CPUs are implemented and work (I even took VLSI and CPU design courses in university, though things have moved along quite nicely since those days!)

    Personally I prefer the flexibility of multiple-inheritance, but I am thoroughly addicted to the cross-platform nature of Java. My favourite is actually the C# syntax, but realistically the Mono implementation is so slow and outdated that it may as well exist -- C# is effectively Windows-only.

    Maybe one of these days I'll play with PHP, but I'm really not a "web guy". Most of my experience is with back-end data services, relational-object modeling, and making batch jobs and huge complex reports run like a bat out of hell. PHP feels too much like Visual Basic or other "integrated" GUI/IDE/Code environments for my tastes. I'd rather work on and provide glue layers for scalable JEE systems than tie myself to a language whose libraries aren't inherently designed for cluster-scaling.

    --
    I do not fail; I succeed at finding out what does not work.
  24. Re:advantages of multiple inheritance by K.+S.+Kyosuke · · Score: 2

    Multiple inheritance is supported in some form or another in just about every OO language in existence. It's just that most prefer to restrict multiply-inherited traits to methods and call them "interfaces" instead of "base classes."

    Theory Alert: That's not inheritance, that's subtyping. The difference is subtle, yet important. Inheritance is reuse of implementation, subtyping is a matter of type compatibility (Liskov's substitution principle). In rather basic OOP languages, such as Java, inheriting a class implementation immediately generates a subtype - which is probably the reason why it confuses a lot of people - but it's not a general principle. (E.g., type systems with the MyType construct generate a subclass by inheriting a class but that subclass is not always a subtype.)

    --
    Ezekiel 23:20
  25. Re:advantages of multiple inheritance by rev0lt · · Score: 2

    Actually, you *do* have exceptions. And traps. And aborts. In x86/ia32, the first 32 interrupt vectors are reserved for cpu exceptions. In all modern x86 operating systems, virtual memory is managed trough (you guessed it) exceptions.

    Regarding the if/else blocks, they are a bit like the bad programmers that use goto because they can't process anything else. How do you think those fancy exception structures are translated? You can quicly slap one of a dozen variants on an assembly project. An easy lazy version? At a given point, you have a var with the offset of the common error handling routine, and you pass as a parameter the error code you want to use and (optionally) the severity. Have a macro created that does something like (push errorCode / call [_errorHandler]). Your error routine will quit on fatal errors, or return to the execution (or change the return path in the stack) just like any other function. the iteration to get error messages? Use arrays of offsets, then add the base address of the offset array to the error code, and this step is similar to many other languages (but in asm you can have funcion offsets to call for specific handlers without using complicated object inheritance).

  26. Re:advantages of multiple inheritance by Xest · · Score: 2

    Sorry, you've lost me, is this meant to be an example of multiple inheritance being used or abused? I get the intention you feel it's the former, but the reality is it's the latter.

    Your example proves the point precisely - multiple is never necessary, hardly ever useful, and even people like yourself who greatly believe in it seem to completely miss the fact that you've used it for something that could've been done far better without it.

    Your anecdote doesn't speak in favour of multiple inheritance - on the contrary, it's an example of why it's a problem, it gets used for things it simply shouldn't. Your example is a fine demonstration of poor architecture and a failure to properly achieve separation of concerns.