Code Golf tournaments have been gaining popularity lately. They are, in essence, contests to determine who can write the shortest code to perform a function. Two recent popular PHP code golf entries are Twitto, a web framework in under 140 characters, and Twittee, a dependency-injection container in under 140 characters. While they may not have all the security features and validation required of a production application, they are a good demonstration of programming skill and capabilities of a programming language.
N4 Express
Drupal SQLite Installation Bug
June 20, 2012
If you are using SQLite as the database for your Drupal installation, make sure you do not specify a database prefix because it alters the filename and the altered filename is invalid on Windows-based systems.
The Drupal UI isn’t perfect and the input validations aren’t fool-proof. However, they do have a very powerful set of modules to serve as a platform for rapid application development and that remains its unique selling point.
WordPress 3.3.2 Released
April 21, 2012
WordPress version 3.3.2 was released today. It contains security updates and makes a bunch of fixes to users of WordPress 3.3.x prior to the release of WordPress 3.4.
Here are some of the changes made:
- Adobe Flash objects used for uploading were updated (Plupload as well as SWFUpload and SWFObject)
- Fixes a cross-site vulnerability problem while posting comments and creating hyperlinks
- Fixes a case when an administrator can disable a network-wide plugin
You can read more about the new version here.
Design Patterns With PHP 5.3
March 1, 2012
CodeIgniter: Call to a member function library/helper() on a non-object
February 23, 2012
When using CodeIgniter, a lot of developers get the “Fatal error: Call to a member function library() on a non-object” or the “Fatal error: Call to a member function helper() on a non-object” error. What needs to be understood is that the base class being used has a constructor that should be called to initialize it. Defining a constructor means that the base class has to be called explicitly with a “parent::__construct();”. It should prevent the $this->load from evaluating to a non-object and get rid of the “Fatal error: Call to a member function library() on a non-object” or the “Fatal error: Call to a member function helper() on a non-object” error.
WordPress Themes: Organizing functions.php
February 22, 2012
If you are building a WordPress theme from scratch or using another theme to do the ground work for you, there are certain things you probably want to do to tidy up your code, especially if you want to get your theme listed in the WordPress Theme Directory at some point in time.
To start off with, you should be getting the functions that register the menu or registering theme support for capabilities, such as feed URLs, attached to the ‘after_setup_theme’ hook rather than the ‘init’ hook, which is the approach that some theme authors tend to use.
I would also suggest that you put all of your add_action, add_filter, and add_shortcode statements in one section of your functions.php instead of having a mix of functions and add statements so they are easier to find. Having comments to indicate the separation between sections like the old C developers did to separate function prototypes from the function implementations would help too.
Finally, if you are using hard coded URLs within your source code and intend to distribute your theme rather than use your theme for a specific client’s website, you have to replace the hard-coded string with something that can be configured within a theme settings page.
Handling WordPress Plugin Dependencies
February 18, 2012
If you have a plugin that is dependent on another plugin, you probably want to have that other plugin activated when your plugin is activated.
One way to do that is to get the array of active plugins by getting the return value of “get_option(‘active_plugins’);”, placing the plugins you want to have activated into that array, and using “update_option(‘active_plugins’, $plugin_array);” to update the list of active plugins.
It is difficult to create a user experience if you are doing things that the user does not expect, so I would probably suggest that the best way to activate another plugin would be to display a button or a link for the user to click on to activate the other plugin.
KNR MultiFeed 0.6 Released
February 16, 2012
A new version of the KNR MultiFeed plugin, version 0.6, has been released, providing the ability to use short codes to display news feeds within pages or posts. It also fixes problems with the sort order that crept in during code refactoring.
toString in PHP
February 5, 2012
Just as you can define a toString() method in programming languages such as Java and C#, you can have __toString() magic methods for PHP classes too.
The advantage of using __toString() in PHP is that you can use object variables with echo or print directly. Also, you can avoid the PHP error ‘Catchable fatal error: Object of class xyz could not be converted to string in filename.php on line x’ when accidentally passing an object variable to an echo or print statement.
Take a look at this example:
class Car { var $brand; var $modelName; var $modelYear; public function __toString() { return $this->brand.' '.$this->modelName.' '.$this->modelYear; } }
The Car class has a __toString() method that returns a string representing the object. The Car class can be used as follows:
$car1 = new Car(); $car1->brand = 'Toyota'; $car1->modelName = 'Camry'; $car1->modelYear = '2010'; echo $car1;
This example returns the output: “Toyota Camry 2010″
In the absence of the __toString() method, PHP would have returned the error “Catchable fatal error: Object of class Car could not be converted to string in example1.php on line 17″.
Boozurk 1.04 WordPress Theme Released
January 29, 2012
The Boozurk WordPress Theme is now listed in the WordPress Theme Directory after a long wait for a review. While the theme is does not get brownie points for being more visually appealing than the average theme, it does do provide a simple theme with lots of functionality. The icons on the lower right of the screen lets you quickly navigate through a site and the theme can provide usable links for pages and posts without titles too.
The theme can be modified to improve its looks and has a good deal to offer to folks who pick up free themes and add a more premium feel to the themes for their clients.
