Make WordPress Core

Opened 13 years ago

Closed 13 years ago

Last modified 13 years ago

#7742 closed defect (bug) (wontfix)

wp-cron functions not accepting array(&$this,'callback') as a callback

Reported by: arena Owned by: jacobsantos
Milestone: Priority: high
Severity: normal Version:
Component: General Keywords:
Focuses: Cc:


wp-cron functions not accepting array(&$this,'callback') as a callback

Change History (7)

#1 @jacobsantos
13 years ago

  • Keywords reporter-feedback added

Can you give code snippet of what you are trying to do?

#2 @jacobsantos
13 years ago

  • Keywords reporter-feedback removed

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.

#3 @jacobsantos
13 years ago

I'm going to do some tests and see what the outcome is for the database. If the $this correctly names the object, then it can be used. It might be that the solution restricts to static method calls and functions.

#4 @jacobsantos
13 years ago

  • Owner changed from anonymous to jacobsantos

#5 @jacobsantos
13 years ago

  • Status changed from new to assigned

#6 @westi
13 years ago

  • Resolution set to wontfix
  • Status changed from assigned to closed

This feels like something that is unlikely to work.

You are creating a referenced object in one run of WordPress and expecting it to exist in another one.

Just register a function as you hook and call into your class from there.

#7 @westi
13 years ago

  • Milestone 2.7 deleted
Note: See TracTickets for help on using tickets.