Views (Site)

Generate a PHP Error

It may seem odd to deliberately create PHP errors, but it's a useful test. PHP errors do occur from time to time in both Joomla and in extensions, especially if you have old extensions and upgrade your PHP version. You should make sure that your site can handle all of these errors properly, i.e. without alarming the user, and preferably sending you an email to inform you of the error.

Create a menu item of type LADkit, Generate an Error. If you do this on a live site, create the menu item on a hidden menu. The front end view looks like this.

LadKit-9.1

Select the error you want to generate and click the Go button. Test all of the errors and make sure you are happy with the way your site handles them. The results depend on the Error Reporting setting in Joomla Global Configuration, and the error handling provided by your site template. You might be surprised how badly some templates handle some of these errors.

Test Error
Undefined variable
$a = $b;
Notice: Undefined variable.
Array syntax deprecated
$a = 'abc'; $b = $a{2};
PHP < 7.4 - No error.
PHP 7.4 - Deprecated: Array and string offset access syntax with curly braces is deprecated.
PHP 8 - Fatal error: Array and string offset access syntax with curly braces is no longer supported.
Creating default object from empty value
$a->x = 1;
PHP < 5.4 - No error.
PHP >= 5.4 - Warning: Creating default object from empty value.
PHP 8 - Attempt to assign property "x" on null
Call to undefined function.
abc();
Call to undefined function
Divide by zero
$a = 0; $b = 1; $c = $b/$a;
Warning: Division by zero.
Unhandled exception
throw new Exception('LADkit Exception Test');
LADkit Exception Test.
Unsupported operand types
$a = 'a' + 1;
PHP < 7.0 - No error.
PHP 7 - Warning: A non-numeric value encountered.
PHP 8 - Fatal error: Unsupported operand types: string + int.
Strftime deprecated
$a = strftime('Y');
PHP < 8.1 - No error
PHP 8.1 - Function strftime() is deprecated