Health Check Error: Found usage of array functions on $_SESSION in files
Overview
The Health Check wizard must be run when upgrading order to evaluate whether your instance is suitable for upgrade. During the health check, various types of issues may be detected which can affect your ability to upgrade to Sugar 7. This article will cover how to resolve a "Found usage of array functions on $_SESSION in files" error reported by the health check.
Symptoms
This error generates an output similar to the following in health check:
Resolution
To address this issue, the responsible customization will need to be modified before proceeding with the upgrade. The generated error message will help determine the contents of the file causing the health check error. We will use the following error message as an example:
Found usage of array functions on $_SESSION in files: 'custom/myfile.php' using $_SESSION with array function 'Array'.
This example provides the file (./custom/myfile.php
) where the error occurs. Opening the file, we find that the code contains is_array
being used in conjunction with $_SESSION
in line 3 of the file.
<?php
// file location: custom/myfile.php
if (is_array($_SESSION['foo'])) {
Use of the following array functions is not allowed on $_SESSION in Sugar 7.x and above:
is_array
in_array
array_keys
array_merge
For Sugar 7.x, the $_SESSION
is now an instance of PHP ArrayObject (which is described on this site), and a function like is_array
will need to be replaced with a call to \Sugarcrm\Sugarcrm\Util\Arrays\ArrayFunctions\ArrayFunctions::is_array_access
.
The corrected line of code should look similar to this:
<?php
// file location: custom/myfile.php
if (ArrayFunctions::is_array_access($_SESSION['foo'])){
Once the necessary change has been made, please navigate to Admin > Repair and perform a "Quick Repair and Rebuild" to ensure that the changes are synced between the application and database.
Perform the health check again to confirm that the error is no longer reported.