PhpSandbox\PHPSandbox::prepareVars PHP Méthode

prepareVars() protected méthode

Prepare defined variables for execution
protected prepareVars ( ) : string
Résultat string Prepared string of variable output
    protected function prepareVars()
    {
        $output = [];
        foreach ($this->definitions['variables'] as $name => $value) {
            if (is_int($name)) {
                //can't define numeric variable names
                $this->validationError("Cannot define variable name that begins with an integer!", Error::DEFINE_VAR_ERROR, null, $name);
            }
            if (is_scalar($value) || is_null($value)) {
                if (is_bool($value)) {
                    $output[] = '$' . $name . ' = ' . ($value ? 'true' : 'false');
                } else {
                    if (is_int($value)) {
                        $output[] = '$' . $name . ' = ' . ($value ? $value : '0');
                    } else {
                        if (is_float($value)) {
                            $output[] = '$' . $name . ' = ' . ($value ? $value : '0.0');
                        } else {
                            if (is_string($value)) {
                                $output[] = '$' . $name . " = '" . addcslashes($value, "'\\") . "'";
                            } else {
                                $output[] = '$' . $name . " = null";
                            }
                        }
                    }
                }
            } else {
                $output[] = '$' . $name . " = unserialize('" . addcslashes(serialize($value), "'\\") . "')";
            }
        }
        return count($output) ? "\r\n" . implode(";\r\n", $output) . ";\r\n" : '';
    }
PHPSandbox