6.2. Callback Function Access
Prev | Chapter 6. Callbacks | Next

## 6.2. Callback Function Access

By default, the callback function has access only to the GD image resource as the $img argument, the pass-through argument provided when the callback function was registered, and additional arguments (if any) provided by PHPlot for the callback. It does not have access to the PHPlot class object instance, nor any of its contents.

If you need access to the internals of the PHPlot class instance from your callback, you have three options.

1. You can declare your PHPlot class instance variable as global.

2. You can pass the instance variable as the $arg when registering the callback. With PHP5, this will pass a reference to the object, which allows reading and changing variables. (PHP4 would pass a copy of the object at the time the callback function is being set up, which would probably not be useful. There are work-arounds, but PHP4 is no longer supported.)

3. You can use a class method which extends PHPlot. This is described in Section 6.4, “Object Methods as Callbacks”.

As stated in the warning at the top of this chapter, any access to the class internals is risky and subject to break with any new update to PHPlot.

Prev | Up | Next
Chapter 6. Callbacks | Home | 6.3. Available Callbacks