Chapter 9. Callbacks

Abstract

This chapter documents the callback feature in PHPlot. Callbacks allow a programmer using PHPlot to insert their own functions into the graph drawing process. Callbacks are currently also used for development and testing of PHPlot.

Warning

Callbacks were added to PHPlot-5.0.4 as an experimental feature. This feature is subject to change in future releases. Changes in the implementation may be incompatible with the current interface. The feature may even be removed entirely. Be aware of this before you decide to rely on callbacks in your application.

Some methods of using callbacks allow you to directly access or alter PHPlot class variables, or call PHPlot internal methods. (Of course, this is currently possible without the callback feature as well.) All PHPlot class variables, and all methods/functions which are not documented in the "Reference" section of the PHPlot Reference Manual, are considered to be for internal use and are subject to be changed or removed at any time.

9.1. Callbacks Application Interface

Refer to these entries in the Function Reference:

Either a function name or an object and method can be registered as a callback with SetCallback. For more information about using callbacks with objects and methods, see the PHP manual under Types, Pseudo Types, Callback. Also refer to Section 9.4, “Object Methods as Callbacks” later in this manual. Whether calling a function or an object method as a callback, the same calling sequence is used.

function_name($img, $passthrough_arg, [other_args...])
  

$img

The GD image resource for the plot image.

$passthrough_arg

The third argument supplied to SetCallback ($arg) when the callback is established. This allows the programmer to pass information to the callback without using global variables. This can be any PHP type including array. To pass a reference, you should put it into an array and pass the array.

other_args...

Zero or more additional arguments supplied by PHPlot to callbacks of this type. Refer to Section 9.3, “Available Callbacks” to see what callback reasons supply extra arguments.

For example, given this callback setup:

$plot->SetCallback('draw_graph', 'my_drawing_callback', $myvar);
  

Then PHPlot will call:

my_drawing_callback($img, $myvar_value);
  

Where $myvar_value is the value of $myvar at the time SetCallback was called.