Reputation: 110
I came across a Wordpress widget that looked something like this
class my_widget extends WP_Widget {
function my_widget() { return self::__construct(); }
function __construct() {
// Some code here
...
}
}
add_action( 'widgets_init', create_function( '', "return register_widget('my_widget');" ) );
The __construct() will be invoked when an object is created. What help or functionality does the my_widget() function provide? Is it really needed? Any significance of that function having the same name as the class?
Upvotes: 1
Views: 260
Reputation: 160833
This just provide the backward compatibility for PHP4, nothing else.
For PHP4, my_widget
is the constructor method, so it have to call __construct
explicitly.
Upvotes: 1
Reputation: 3464
Looks like compability with PHP4... I would say that this code is weird.
Upvotes: 0