News Feed
Sections




News Archive
Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

IBM developerWorks:
Going dynamic with PHP
February 09, 2006 @ 06:53:35

The IBM developerWorks section has posted a new tutorial on their site dealing with the creation and use of dynamic objects, member variables, and methods on the fly with PHP.

Objects are a double-edged sword. On the one hand, objects are a great way to encapsulate data and logic and create a more maintainable system. On the other hand, they can become verbose and require that you write a lot of redundant code where the best you can hope for is not to make any mistakes.

Three solutions are available to you. The first solution is simply to sit down at the keyboard and type for a while. That's fine for small projects, but I'm lazy. The second solution is to use a code generator that reads the database schema and writes the code for you. That's a great idea and a topic for another article. The third solution, which I cover in this article, is to write a single class that dynamically molds itself at runtime to the fields of a given table.

The tutorial walks you through the creation of this "bendy class" in the context of accessing a database through PHP. It uses the PEAR DB package to actually make the connection, but that's easily adapted to any database layer. All of the code is laid out for you, progressively getting more complex, with explainations for every step of the way. They even include methods for logging information about the connections made via a simple wrapper.

0 comments voice your opinion now!
dynamic class method member object database PHP5 dynamic class method member object database PHP5


blog comments powered by Disqus

Similar Posts

Kian Hui Teo\'s Blog: Switching between PHP 5.1.x and Zend Core for Oracle

Pavel Shevaev's Blog: A reliable way to serialize/unserialize objects in PHP

DevShed: Working with Prepared Queries with PDO Objects in PHP 5

Michael Nitschinger's Blog: Quick Tip: Lithium Redirect

DevShed: Adding Validation to an Image Generator Class with PHP 5


Community Events

Don't see your event here?
Let us know!


list php7 example composer language series project framework podcast interview programming symfony application part2 laravel yii2 api opinion introduction community

All content copyright, 2015 PHPDeveloper.org :: info@phpdeveloper.org - Powered by the Solar PHP Framework