[wp-hackers] Re: [wp-trac] Re: [WordPress Trac] #3875: Proposal for a new plugin architecture

jacobsantos at branson.com jacobsantos at branson.com
Tue Jul 31 18:08:13 GMT 2007


Fascinating that we had similar solution. However, from what I have 
seen, your solution would only half work.

The magic method __toString(), which could be anything by the way you 
call it, would only print out what was in the __toString() only with 
echo or print, before 5.2. It seems like the most logical choice, since 
if they are using PHP 4, then it would just call the method and pull 
down the result. Very nice. For your example to work, they would have to 
use a static member which they increment each time __toString() is 
called. Not difficult. This documentation would have to be added for 
plugin developers. This only directly affects those who use classes.

The value in __toString() would have to change. However, the current 
code would only need to be changed like so.

{{{
$fn_idx = (method_exists($obj,'__toString') ? $obj->__toString() :  '') 
. '[]' . get_class($obj) . '[]' . $fn;
}}}

I'm not sure this would work correctly.

For array('class_name', 'method_name') :

$fn_idx would equal: '[][]method_name'

For array($this, 'methodname') : ($this (myClass) having __toString that 
return 'object')

$fn_idx would equal: 'object[]myClass[]methodname'

Another For array($this, 'methodname') with same as above:

$fn_idx would equal: 'object[]myClass[]methodname'

It solves nothing if casted as a string when added to the array key 
value. From my experience, casting it as an array would very well give 
an error. You appear to be better developer than I. If you can solve 
this, then let me know because the only way I was able to get around 
this was casting as a string.

'''Inheritance'''

If a plugin developer wises to add the same class, why don't they just 
inherit their class and use that instead?

{{{
class Foobar {
    var $name;
    
    function Foobar( $name ){
        $this->name = $name;
    }
    
    function hook( $v ) {
        return $this->name . " Hooked! $v";
    }
}

class Barbar extends Foobar { }

$foo1 = new Foobar("baz");
$foo2 = new Barbar("quux");

create_filter( 'the_content', array( &$foo1, "hook" ) );
create_filter( 'the_content', array( &$foo2, "hook" ) );
}}}

As much work as they would have to do to comply with the new standards, 
it would be just as easy to extend their or another's class with a new name.

{{{
$wp_filter[$tag][$priority][serialize($serialized)][] = //...
}}}


More information about the wp-hackers mailing list