Chapter 6. Callbacks
Prev | Part I. PHPlot Programming | Next

## Chapter 6. Callbacks

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.

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.

## 6.1. Callbacks Application Interface

Refer to these entries in the Function Reference:

- SetCallback - Register a callback function

- GetCallback - Return a currently registered callback function

- RemoveCallback - Unregister a callback function

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 and the documentation for the PHP call_user_func function. Also refer to Section 6.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 6.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, $plot_area);

Where $myvar_value is the value of $myvar at the time SetCallback was called. (The plot_area parameter is only supplied for the draw_graph callback in PHPlot-5.1.0 and later.)

Prev | Up | Next
5.24. Example - Using Truecolor To Make a Histogram | Home | 6.2. Callback Function Access