[wp-trac] Re: [WordPress Trac] #7742: wp-cron functions not accepting array(&$this, 'callback') as a callback

WordPress Trac wp-trac at lists.automattic.com
Mon Sep 15 15:27:14 GMT 2008


#7742: wp-cron functions not accepting array(&$this,'callback') as a callback
---------------------+------------------------------------------------------
 Reporter:  arena    |        Owner:  anonymous
     Type:  defect   |       Status:  new      
 Priority:  high     |    Milestone:  2.7      
Component:  General  |      Version:           
 Severity:  normal   |   Resolution:           
 Keywords:           |  
---------------------+------------------------------------------------------
Changes (by jacobsantos):

  * keywords:  reporter-feedback =>

Comment:

 Confirmed. The issue stems from using the {{{$hook}}} parameter in the
 cron array. PHP doesn't do array as keys well or in this case, not at all.
 The correction will require a major update to the code. However, in the
 mean time, one possible "fix" for the reporter is to use the 'callback'
 argument and name the hook as a string. The 'callback' argument hook will
 be called and since it is serialized will work. Actually, no it won't
 work.

 The problem with {{{array(&$this,'callback')}}} is both that it is
 serialized, meaning that the reference most likely is going to be lost.
 Secondly, it is stored in the database, therefore when it falls back out
 into PHP execution, &$this is most likely going to become $this, which is
 going to reference the object.

 The solution, then would be to use static method calls. Instead of
 {{{array(&$this, 'callback')}}}, use {{{array('objectname', 'callback')}}}
 instead. You will have to change the method, because you won't have access
 to {{{$this}}} and either need to use {{{self::}}} or {{{objectname::}}}
 depending on what version of PHP you want to support.

-- 
Ticket URL: <http://trac.wordpress.org/ticket/7742#comment:2>
WordPress Trac <http://trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list