Problems with php7

4,008 views
Skip to first unread message

Ben Barker

unread,
Jul 30, 2016, 4:20:57 PM7/30/16
to JpGraph
I have been using jpgraph without problems with php 5 for some time. 
I am now trying to get it to run with php7, and have downloaded the latest version from the website

However, any attempt to use the library now gives me: 

PHP Fatal error:  Uncaught TypeError: Argument 1 passed to JpGraphException::defaultHandler() must be an instance of Exception, instance of Error given in ...../jpgraph/jpgraph_errhandler.inc.php:158

I suspect whatever is wrong is very basic...but I can't seem to track it down. Any ideas...? 

Pandora

unread,
Aug 18, 2016, 5:15:13 AM8/18/16
to JpGraph
Hello,

Php7 changed the exceptions. All fatal errors and catchable fatal errors are now engine exception.
Previously the fatal errors could have been caught and handled using set_error_handler.
But with php7 they are now \Error exceptions wich be no longer be catchable in set_error_handler.

To try something you can try to use a 
try{
//code
}catch(Throwable $t){
  var_dump($t);

You will see your problem.

Rick WIdmer

unread,
Dec 24, 2016, 5:33:31 AM12/24/16
to JpGraph
Quick & Dirty fix: 

in file:  jpgraph-4.0.?/src/jpgraph_errorhandler.inc.php  at line: 158  Change  'defaultHandler(Exception' to defaultHandler(Error'.

That may open up other holes, but it catches fatal errors and allows you to see the real error message.

Robert Burgholzer

unread,
Jan 7, 2017, 11:10:47 AM1/7/17
to JpGraph
Rick - that gets one through the first hoop, but predictably, somewhere later in the process it triggers its counterpart:
   PHP Fatal error:  Uncaught TypeError: Argument 1 passed to JpGraphException::defaultHandler() must be an instance of Error, instance of JpGraphExceptionL given in jpgraph-4.0.2/src/jpgraph_errhandler.inc.php:159



David Marcus

unread,
Feb 20, 2017, 4:48:42 PM2/20/17
to JpGraph
To get jpgraph-4.0.2 to work with PHP 7, I had to make these changes:

Functions passed to set_exception_handler must declare their argument as Throwable instead of Exception (or not declare a type to work with both PHP 5 and 7), i.e., defaultHandler, ErrHandlerImg, ErrHandlerPS.

Constructors must be named __construct, not the class name, e.g., LinePlot.

Robert Burgholzer

unread,
Mar 2, 2017, 8:34:36 AM3/2/17
to JpGraph
David - thanks for this advice - would you be willing to share a diff for the jpgraph library? Or maybe you could copy/paste one example function that you changed?

BTW - are folks using GitHub to handle contributions and if so, is this the correct project? https://github.com/ztec/JpGraph

Thanks!  

Benoit Pesty

unread,
Jun 21, 2017, 4:10:56 AM6/21/17
to JpGraph
Got the same problem with the Error instead of Exception.

YielooCedric did the job of correcting the constructors and merged the correction for the Throwable, i think his fork should be one to use for PHP 7 : https://github.com/Yieloo/JpGraph

Regards,
Reply all
Reply to author
Forward
0 new messages