[wp-hackers] Passing class methods by reference

Jacob Santos wordpress at santosj.name
Sat Aug 7 23:25:57 UTC 2010


I think the point is that both static method and functions are faster than
dynamic referencing of the method.

In truth, the benchmarks I've seen is not worth using one over the other
based on performance alone. Now I'm not quite sure what the issue is,
accessing variables is different from the overhead incurred with creating
the local scope of the method and function. That overhead is close enough to
not even matter.

There is a benchmark online between accessing globals, static class
properties, class properties, class constants, $this, self, etc. It might be
a look. However, 5.3 might have changed the speed somewhat. From what I can
remember, globals would be quickest, since $GLOBAL is a straight lookup
stored in the PHP space. Accessing any class requires accessing the class
memory space which will incur a bit of overhead.


On Fri, Aug 6, 2010 at 4:29 PM, Michael D Adams <mda at blogwaffe.com> wrote:

> On Fri, Aug 6, 2010 at 2:25 PM, Mike Schinkel
> <mikeschinkel at newclarity.net> wrote:
> > On Aug 6, 2010, at 5:20 PM, Michael D Adams wrote:
> >> Sorry - I meant compared to straight functions.  The context (in my
> head) was
> >>
> >> $object_i_can_use = My_Class::instance();
> >> vs.
> >> $object_i_can_use() = my_class_instance();
> >>
> >> Where the former stores the as a static property or variable, and the
> >> later accesses a previously created global.
> >>
> >> I didn't actually benchmark that specific scenario, though, so I
> >> probably shouldn't even have mentioned it :)
> >
> > I guess the important question is, is the performance different
> significant enough to matter in the context of WordPress plugins?
>
> I doubt it. (But there I go again saying things without benchmarking them.)
> _______________________________________________
> 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