View unanswered posts | View active topics It is currently Thu Mar 28, 2024 5:52 pm



Reply to topic  [ 2 posts ] 
[Fix] Static Method callback 
Author Message
New pChart user
New pChart user

Joined: Thu Oct 27, 2011 12:01 am
Posts: 2
Post [Fix] Static Method callback
Hi guys, I've found a bug while trying to use a static method (custom callback) for formatting my axis values.
Those two valid callbacks (based on PHP standards for callbacks) fails on [pDraw.class.php ~ ln 3133, is_function function]:
Code:
...
$pData->setAxisDisplay(0, AXIS_FORMAT_CUSTOM, 'class::method');
...

and
Code:
...
$pData->setAxisDisplay(0, AXIS_FORMAT_CUSTOM, array('class', 'method'));
...

(Both are valid callbacks!)

I fixed it by changing (on pDraw.class.php ~ ln 3133):
Code:
...
if(function_exists($Format)) {
...

for:
Code:
...
if(is_callable($Format)) {
...


As is_callable is available since PHP 4 >= 4.0.6, I think we will not have problems with Backward Compatibility. It's also the recommended way to check for valid and compatible callbacks those times....
Then, every instance method, static method or simple function can be used.

Maybe it could be added to the next minor...
Oh, and Jean, thanks for the awesome library! :)


Thu Oct 27, 2011 12:16 am
Profile
pChart user
pChart user

Joined: Wed Oct 05, 2011 9:18 am
Posts: 4
Post Re: [Fix] Static Method callback
I just wanted to push this bug report, as I ran into the bug:

Providing a method as callback for AXIS_FORMAT_CUSTOM produces a warning message, which leads to corruption of the image file, when directly sent to the browser.

Code:
class SplineChart {
        /* snip */
        public function plot() {
                /* snip */
                $dataSet->setAxisDisplay(0, AXIS_FORMAT_CUSTOM, array($this,"yAxisFormat"));
                /* snip */
        }
        function yAxisFormat($value) {
                /* snip */
        }
}


Message produced by server:

Code:
Warning: function_exists() expects parameter 1 to be string, array given in C:\xampp\htdocs\MeasurementServer\pchart\class\pDraw.class.php on line 3134


The fix suggested by willybarro works perfectly for me.

with best regards and thanks for your awsome work,
Emi


Wed Feb 29, 2012 10:28 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 2 posts ] 

Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron