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."
- 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.This page actually has alot of links of changes and new features. What's New
-- Brought to you by Carl's JR
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.
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.= rss1
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
http://www.k5n.us
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.
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.
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.
There is an implementation of this idea (and more) in PEAR's DB_DataObject package:
- dataobject.php
http://pear.php.net/manual/en/package.database.db
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.
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.)
My firm is a fairly big fan of WASP (http://wasp.sourceforge.net/). Check it out.