Joomla errorhandling with PHP7

279 views
Skip to first unread message

Ove Eriksson

unread,
May 4, 2016, 3:52:35 AM5/4/16
to Joomla! CMS Development
I know that PHP7 has changes in the errorhandling. Now I don*t know if my problem depends on this change, some change in Joomla or my own settings for errorhandling. As far as I understand I have set everything to the max level. Joomla settting = Maximum, php.ini the same and XDEBUG is installed.

I do not get any hints on where (PHP-script) an error is created and no linenumber.

e.g. Error displays in backend (isis) as "An error has occured", "[0] Call to a member function getKeyName() on boolean"
Nice on a live site but not when coding.

I had a look in the error object and there I find both the PHP filename and the linenumber. AND the whole XDEBUG trace.

Is it a probleme of mine somewhere?

I made a change to Isis error page to get the filename and linenumber.

System: Joomla 3.5.1, XAMPP, PHP 7.0.4, Windows 10

My quick fix in isis error.php. Added in the debug part.


                    if ($this->debug) : ?>
                       
<p>
                           
<span><?php echo $this->error->getFile(); ?></span>
                        at
line
                           
<span><?php echo $this->error->getLine(); ?></span>
                       
</p>                
                       
<?php echo $this->renderBacktrace(); ?>
                   
<?php endif; ?>



ghazal

unread,
May 4, 2016, 4:51:30 AM5/4/16
to Joomla! CMS Development
Hello,
why don't you post this on github. Expert devs will check your code and it could even be accepted.

Category:GitHub - Joomla! Documentation ->
https://docs.joomla.org/Category:GitHub

Working with git and github - Joomla! Documentation ->
https://docs.joomla.org/Working_with_git_and_github

Using the Github UI to Make Pull Requests - Joomla! Documentation
-> https://docs.joomla.org/Using_the_Github_UI_to_Make_Pull_Requests

Ove Eriksson

unread,
May 4, 2016, 5:31:31 AM5/4/16
to Joomla! CMS Development
I first wanted to know if it*s a general problem or a problem of mine with my settings for errorhandling.
I also do not know what happens with my quick fix if error reporting is set to none.

Michael Babker

unread,
May 4, 2016, 8:03:57 AM5/4/16
to joomla-...@googlegroups.com
As long as the error object implements the Throwable interface (Exception and the new Error class in PHP 7 do so, so everything subclassed from there has it), JDocumentError::renderBacktrace() should be able to process it without issue.  If you aren't getting a usable output from that function, I'd say make sure that the error object's getTrace() method is actually returning an array with the keys the render method is expecting (unless something changed against PHP 7 that didn't hit any of the docs it shouldn't have needed any changes).

--
You received this message because you are subscribed to the Google Groups "Joomla! CMS Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email to joomla-dev-cm...@googlegroups.com.
To post to this group, send email to joomla-...@googlegroups.com.
Visit this group at https://groups.google.com/group/joomla-dev-cms.
For more options, visit https://groups.google.com/d/optout.

Ove Eriksson

unread,
May 4, 2016, 11:55:41 AM5/4/16
to Joomla! CMS Development
Hi Michael,


To illustrate what I get I made a screen snippet.
The yellow line is what I added to the Isis error.php.
As you can see, I made a typo in articles.php at line 56.

I do not get this info from the Backtrace renderer. It is in the error object but not in the array created from the object. ( I didn't find that method)

I do not get any other messages.

Michael Babker

unread,
May 4, 2016, 12:11:31 PM5/4/16
to joomla-...@googlegroups.com
That method's in PHP core so you're not going to find it unless you dig into the PHP source and can read C code.

FWIW, I just checked the call stack on a PHP 5.6 and 7.0 install and in both the stack doesn't include the exact class/method/line that the Throwable was thrown from, rather it's the trace of steps getting you into that function/method.  So as is, everything is displaying as intended.  XDebug when it renders error messages gives you basically a concat of the exception's message, file, and line but Throwable doesn't have a method that gives you a string with all this data.

So technically your "hack" is right if you want to add that to your output, but needing it isn't because of a change in any error handling layers.  It's just how Throwable objects are structured.

Ove Eriksson

unread,
May 4, 2016, 3:38:47 PM5/4/16
to joomla-...@googlegroups.com

Michael,

Is it only some php errors (fatal ) that end up on the error page? I tested with an old well known error. In XDEBUG, if  it's activated otherwise as plain text on the page.

Notice: Only variables should be assigned by reference in D:\xampp\htdocs\j3\administrator\components\com_comp\models\menu.php on line 49

Do you know if it's possible to turn off XDEBUG error reporting but still be able to run debug sessions?

If someone gets errors as I have described, they can use my quick fix. Or is it of general interest as a JIssue?

The frontend has of course the same behavior.

Michael Babker

unread,
May 4, 2016, 3:44:59 PM5/4/16
to joomla-...@googlegroups.com
JErrorPage::render() is the global exception handler for uncaught Exception/Throwable objects.  So any Throwable not being caught by something lower in the stack will end up there and ultimately render the error page.

Joomla doesn't set a global error handler, so errors like that do not get caught in the error page.  Only Exceptions/Throwables have a top level handler right now.

In theory, one could throw a plugin together that calls PHP's set_error_handler() function to add a non-Exception error handler if they really wanted it.

Reply all
Reply to author
Forward
0 new messages