Opened 5 years ago

Closed 5 years ago

Last modified 5 years ago

#7742 closed defect (bug) (wontfix)

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

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

Description

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

Change History (7)

  • Keywords reporter-feedback added

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

  • 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.

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.

  • Owner changed from anonymous to jacobsantos
  • Status changed from new to assigned
  • 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.

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