[wp-hackers] Plugin API: Unique ID explanation

Chris Jean gaarai at gaarai.com
Fri Aug 7 22:53:33 UTC 2009


Then what you are discussing does directly interest me as I use the
"array(&$this, 'method')" construct often in basically all of my code. I
have my reasons:

   1. Bundling all the code into a class allows me to freely code
      without worrying about variable or function name collisions.
   2. I make use of OOP features such as inheritance that allows for
      rapid code production.
   3. Code that I write ships to people who don't give a flip about PHP
      4 or PHP 5. If my code fails because it's PHP 5-only, they don't
      blame their host, they blame me.
   4. In some of my more advanced projects, I have multiple instances of
      individual classes that communicate using actions and filters.

Getting back to the topic. You're saying that the way I code is a design
flaw. At no point did any documentation say or even hint that even
though latching actions and filters to objects worked, it really
shouldn't be used.

Seems to me that the design flaw is in the add/remove functions. By no
means am I criticizing those who built or worked on it, but if you are
going to claim design flaw, point the finger toward the actual design
that has the flaw rather than the code the exposes the flaw.

I understand how everything works just fine when using a standard
function or static method, but frankly, that type of solution will not
work for some of my code. Much of my code needs to be instantiated, it's
how things function. Furthermore, some of my code instantiates multiple
instances of a class, each of which needs to have its own unique
action/filter references.

When you mention the overhead, are you saying that the action/filter
calls themselves have overhead or are you saying that using &$this
methods have increased overhead?

The main thing I'd like to know Jacob, is what you are looking for. You
brought up the topic as some sort of call to action. What kind of action
are wanting?

Chris Jean
http://gaarai.com/
http://wp-roadmap.com/
http://dnsyogi.com/



Jacob Santos wrote:
> http://core.trac.wordpress.org/ticket/10535 is the correct link, I
> apologize for the confusion. The point is that people are using:
>
> add_action('whatever', array(&$this, 'method'));
>
> and people are attempting to make it to where if you do,
>
> remove_action('whatever', array(&$this, 'method'));
>
> that it will in fact remove the method from 'whatever'.
>
> Currently, there are many use cases where it still does not. An
> attempt was made in October of 2007 to make it to where it does,
> however, the algorithm was flawed and only worked with a few use
> cases. The attempt is being made now, to extend the use cases that it
> works.
>
> My contention was that instead of working around design flaws used by
> plugin developers that plugin developers should understand that
> functions and static methods do not suffer from the above. Every use
> case will work correctly. Furthermore, the hope to get the code to
> work on PHP4 is a fantasy, a farce.
>
> It is a fun problem with an interesting solution, which is what peaked
> my curiosity. However, these two examples are far better as they don't
> suffer from WTF?s.
>
> add_action('whatever', 'some_function');
>
> add_action('whatever', array( 'some_class', 'some_function' ));
>
> These two examples work with both PHP4 and PHP5.
>
> I'll explain further that as many times as the function is used, it is
> a really bad idea to use the the first example as the overhead is
> quite a bit (overall it is small, but when you start to use it around
> 3000 to 4000 times, the total time just from that function starts to
> exceed 1 second (which is really, really just terrible). Good news is
> that most people will never get around that amount (or so we hope).
>
> Jacob Santos
> _______________________________________________
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
> http://lists.automattic.com/mailman/listinfo/wp-hackers


More information about the wp-hackers mailing list