[wp-hackers] Plugin API: Unique ID explanation
Jacob Santos
wordpress at santosj.name
Fri Aug 7 20:50:22 UTC 2009
Hooks are meant to be a bridge between your code and WordPress. That is,
if you have a bridge going through a building, then you are doing
something wrong. When you have the hook code along with your object
code, then that is exactly what you are attempting to do. It is no
wonder it doesn't work.
I'm not attempting to offend anyone [1], but the question on how to get
an unique ID [2] for objects is the wrong one. The question that should
be asked in my humble opinion [3] WTF are you using the same object to
create the filters and actions in the first place. It isn't a question,
it is an insult. A lot of developers do it and a lot of them probably
are better developers than I am. Why then do I assert it? I'll explain.
The original solution was devised, because it was "good enough" and
worked "well enough." That is, it worked in 10% of the use cases and
well enough to hide flaws in the plugin developers design [4]. The
problem has always been that until spl_object_hash() came along, you can
never be sure that you are working with the same object.
PHP4 is pretty screwed as it relies completely on the original
developers competence and if they have the problem in the first place
[5]. So, if they forget the '&' before $this or $object, then everyone
is screwed. PHP5 has less of this problem, because objects are passed by
reference by default.
Jacob Santos
[1] This is obviously a lie.
[2] http://core.trac.wordpress.org/ticket/10487
[3] The overall design flaw wasn't that the same object being referenced
could no longer be referenced in the future because it would inevitably
change, it was that the same object was being used in the first place.
The fact that static methods and functions don't have this problem needs
to be researched further.
[4] Well, it appears that the only reason it worked, was that the
algorithm was flawed in such a way that it did was it was intended, but
not correctly in such a way that it just hid the bug in a really clever way.
[5] Programmers have different levels of competence in different areas
of programming. Some people can create solutions like you've never seen,
but just really can't do shit about OOP (OOP isn't about putting
functions wrapped in a container with global variables with different
levels of visibility, well it is, but it is more than that and I hate
arguing about that).
More information about the wp-hackers
mailing list