Top 5 new (and cool!) features in PHP5 that you probably haven’t heard of

PHP5 has brought so much new features but because of its big syntax changes, a big percentage of the PHP developing base has not made the change. Here are the top 10 new features that could change your mind.

5: Better error handling with exceptions
I’m sure every PHP developer had been staring at the famous white screen with a “Syntax error” clueless at where the error is really at. With PHP5, you can actually handle PHP errors and do whatever you want with them, but that’s not all. They have also included exceptions which I’m sure most C++ or Java developers use. The good part is that instead of simply failing on with close no errors to you, you could put a few checks before and information you could need such as maybe a print_r() on an array. I have written an article about this: http://vexxhost.com/blog/?p=21

4: Completely rewritten MySQL extension
The MySQL databases are the PHP’s partner in crime. Many developers use this database system in their website’s because it is on of the easiest, free, open-source database software. However, its performance combined with PHP4 was close to poor. Introduced with PHP5 is a newer, rewritten, optimized MySQL extension which was also compatible with MySQL 5.0. It has also introduced other functions such as: Prepared statements, SSL connections, Multi-query functions.

3: A heck of a lot more useful functions
I have a few favorite PHP5 functions which speed up time while coding & enhances the website’s performance. One of my favorites is the __autoload() function – What it does that it would be called if a class that was created and did not exist. It provides you with the class name. This is useful because you don’t need to manage what includes you need for X and Y file and reduces the load for those who simply include all the classes in for every single PHP file. Also, another favorite is file_put_contents() which reduces the 6 lines of code to add something to one.

2: Finally! SQLite database support!
I’m sure a lot of developers will be happy about this one. While MySQL is very popular among most PHP developers, SQLite is much different than it. It actually uses normal files and reads them. It does not need a daemon (or called server) to run in order to execute any queries on it. It makes a better smaller database for these low traffic sites.

1: The best damn OOP support period
PHP programmers have spent an awful of long time trying to create hacks so in order that PHP can make a better OO programming language. Finally, they are rewarded with OO support that either PHP3 or PHP4 can match. It has anything you usually see in most of the other established coding languages. From Constructors, Destructors, Public, protected, private properties & methods, Interfaces, Abstract classes, Class type hints, Static properties and methods, Final properties and methods & a whole suite of magical methods.

That’s the top 5 for me. I hope you think that PHP5 deserves a try! (and we offer it with our hosting plans!)

  • dpw

    php is a joke. give it up…

  • vexxhost

    That’s something I’ve never heard. Any reasons?

  • http://reliablesource.org PafBoy

    Nice, Would like to see more of this :-)

  • vexxhost

    Thanks for your comment, I might be writing another Top 5 if it’s that wanted. :p

  • Radu

    Yes, indeed, quite nice compared to PHP4 and OOP does a great deal in helping you, but there’s still lacking something. I guess it could be a more powerfull debugger, a standard framework, MVC… Who knows?… All I know is after close to half a year of building a CMS, tens of classes, tens of config files and tens of thousands of lines of code it still makes me want to shoot myself in my teeth using a very big gun!

  • Pingback: PHPDeveloper.org

  • philip

    Although it comes with PHP as of 5.2.0 (but available in PECL before this) the Filter extension should be mentioned. As, it’s a pretty big deal. All PHP users will use (and love) it eventually.

  • http://nateklaiber.com Nate K

    PDO is the best thing for databases in PHP (that I have found). Rumor has it to be built into PHP6, but that could be just rumor. PDO does a great job of abstracting the database level and giving you the security of prepared statements and ease of use. I think it’s great.

    For those giving you hassle about PHP: you will have this everywhere. These are the close-minded people that think their programming language is better than everyone elses (but, as above, cant back it up with anything legit). I have used several different programming languages and their corresponding frameworks. I would say PHP is a little behind RoR when it comes to frameworks. There are a few that try to match the ease/functionality in RoR – but they are still lacking.

    Also, the OOP support is nice – but still lacking. OOP was an afterthought with PHP – whereas its at the core of Ruby and Python (and other languages). So, though its nice, I hope it improves even more with the next release.

    Too many people forget that PHP was built as a loosely type scripting language to help people embed code into their pages. At that time, MVC was not as popular as it is now and it solved many problems. However, in solving that problem – at that time – it created more problems for what we see today.

    Every programming language is only as good as the person using it – so the language war doesn’t hold much ground (especially on the internet with trolls like above).

  • http://www.zend.com Kevin Schroeder

    Nate,
    What do you think is lacking in PHP5’s OO support?

  • kenman

    “Here are the top 10 new features that could change your mind.

    5: Better error handling…”

  • http://www.vnideadesign.com KENT

    Anyone can tell me if PHP supports Multi-thread programming. I’m having trouble with timeout handling..

    Email me at: hoangkent@gmail.com

  • http://www.sands-design.net Kelvin Mackay

    Radu –

    Are you aware of the Zend Framework (http://framework.zend.com/)? It’s as close to a standard framework as one could ask :)

  • Pingback: Sands Design Blog - PHP, Web Design, and Ramblings » Archive » Top 5 new features in PHP5 that you probably haven’t heard of

  • Joshua Ross

    Zend Framework is good and MVC, but still beta.

  • http://shoreprogress.com Jake

    Kent,

    Php does not currently support Multi-thread programming… the web by nature is single threaded, one request-one response. If you are having problems with timeouts, you might need to check your web server settings.

  • Pingback: Web Hosting Articles » Blog Archive » Top 5 new (and cool!) features in PHP5 that you probably haven’t heard of

  • http://www.mustywindows.com Craige

    Yes, PHP does in fact have allot of nice new features in PHP 5. The new OOP support is a bliss that we could only dream about in the days of PHP 4, and the mysqli extension is very nice as well. I’m just now getting into exception handling, so I can’t really say much about it, other then it sure beats the old tag method of error handling, in which you had to return a tag of some sort when something failed.

    And PHP does have some nice frameworks popping up. One I recently started working with is CakePHP. It uses the MVC pattern and is based of the RoR framework. You should check it out.

  • http://www.dougalmatthews.com Dougal Matthews

    Very good read.

    I really want to move to PHP 5 (and mySQL 5) but unfortunately my host is slow in offering it. Most annoying.

    I cant wait to get into PHP5 properly.

  • http://www.daholygoat.com/blog/ Leendert Brouwer

    PHP 5 was definitely a leap forward, but the progression was not without compromise, if you ask me.

    – “Better error handling with exceptions”
    Yeah, except that only goes for userland code, not for errors thrown by the PHP interpreter. So now there are 2 ways of error handling, and I don’t like that inconsistence.
    – “One of my favorites is the __autoload() function”
    As long as you know how to handle it, yes, it’s nice. It also invites the use of some nasty switch()-y code. I’ve had the pleasure of reviewing such code – so forgive my bitterness.
    – “The best damn OOP support period”
    Might I say “OOPs”. Sure, it has more OOP support than PHP4 has, but it’s quite far from perfect. It lacks one particular feature that I see a lot in other languages – namespaces. This has annoyed me quite badly from time to time. As a workaround a lot of people invent some very exotic prefixes (*cough*TYPO3*cough*) to maintain large codebases. My most recent clash with this feature was where a migration from PHP4 to PHP5 was needed – did you know that NuSOAP uses some equivalent classnames as the ones in the SOAP extension for PHP5? So we had to write an Adapter to be able to correctly migrate the application, and put all calls through the adapter. There’s more. You talk about the beauty of type-hinting. That’s all nice, but PHP5 doesn’t do type-hinting for the primitive types, only for classes. That’s like a shiny gold invitation card for inconsistent code.

    I realize that the above might have sounded kind of bitter, and to some extent that’s actually correct. But PHP is still one of my favorite languages, despite its shortcomings. You can just quickly whip things up with PHP, and it’s quite powerful all in all. Things like maintaining and enforcing a good coding style in a team for example, is quite hard. So is deploying code from one server to another, because there is a legacy of configuration options that were deprecated over time, to name one example. Think register_globals, magic_quotes_gpc, etc. But, it still has a place in my heart, after using it for about 7 years. Meanwhile, I get to do some projects in other languages, which is great fun because it teaches me to relate better. Have fun coding.

  • http://www.mustywindows.com Craige

    Leendert,

    While namespaces are not OO related I know what you’re saying. They sure would be nice. They may come to us with PHP 6, but I don’t think it has been decided for sure yet.

  • Pingback: DevelopersArena » Top 5 new (and cool!) features in PHP5 that you probably haven’t heard of.

  • http://baranoff.onblogz.com Baranoff

    My five COOL features:
    1. better XML support (SimpleXML, XMLWriter/XMLReader, XSLTProccesor etc)
    2. SPL (standart PHP library). It is awesome!
    3. SOAP
    4. Filter
    5. __toString classes magic method :)

  • http://alsgo.info/pencil-sketch Jersey

    Wonderful and informative web site.I used information from that site its great.b

  • rwei

    Thanks man, i agree

  • http://www.google.com Alex

    Thank You

  • http://www.Collin1000.com Collin

    What about the improved XML support? Thats the biggest deal for me. :D

  • Pingback: #49. Read ‘The 1001 List Of Quality Reads’ « 6ixx