Collections functions
General functions
Node functions
Render functions
Theme permission functions
User functions
Resource functions

override_rs_variables_by_eval()

Description

Run PHP code on array of variables. Used for modifying $GLOBALS.

Parameters

ColumnTypeDefaultDescription
$variables array Array of variables to apply override on.
$code string Signed string containing the PHP code to run.

Return

void

Location

include/config_functions.php lines 1404 to 1456

Definition

 
function override_rs_variables_by_eval(array $variablesstring $code)
    {
    global 
$configs_overwritten;
    
// Remove all previous overwrides that have been set
    
if(is_array($configs_overwritten) && count($configs_overwritten) != 0)
        {
        foreach(
$configs_overwritten as $option => $value)
            {
            if (
$value === 'UNSET_override_rs_variables_by_eval')
                {
                unset(
$GLOBALS[$option]);
                unset(
$variables[$option]);
                }
            else
                {
                
$variables[$option] = $value;
                }
            }
        }

    
$temp_variables $variables;

    
// Copy keys to a new array to prevent loss of original values.
    // This is a temporary solution for PHP versions 7.4 and 8.0 where eval() is applied to the keys in both %$temp_variables and $variables;
    
foreach ($variables as $variable => $var_val)
        {
        
$original['copy_' $variable] = $var_val;
        }

    
extract($temp_variablesEXTR_REFS EXTR_SKIP);
    eval(
eval_check_signed($code)); 

    
$temp_array = [];
    foreach(
$temp_variables as $temp_variable_name => $temp_variable_val)
        {
        if(!isset(
$original['copy_' $temp_variable_name]))
            {
            
$original['copy_' $temp_variable_name] = null;
            }

        if(
$original['copy_' $temp_variable_name] !== $temp_variable_val)
            {
            
$temp_array[$temp_variable_name] = $original['copy_' $temp_variable_name];
            if (
$original['copy_' $temp_variable_name] === null)
                {
                
$temp_array[$temp_variable_name] = 'UNSET_override_rs_variables_by_eval';
                }
            }
        
$GLOBALS[$temp_variable_name] = $temp_variable_val;
        }

    
$configs_overwritten $temp_array;
    }

This article was last updated 27th July 2024 12:05 Europe/London time based on the source file dated 16th July 2024 15:25 Europe/London time.