PHP userland backwards compatibility layer that emulates PHP 5.5+ core functions.

⌈⌋ ⎇ branch:  upgrade.php


Artifact [afcdc26234]

Artifact afcdc262343283f6dba416e708f4d66a5f1abdfd:

  • File ext/var_export54.php — part of check-in [a33d1695b1] at 2014-08-14 07:22:40 on branch trunk — Variant of var_export that utilizes php 5.4 array [] syntax. (user: mario size: 809)

<?php

function var_export54($var, $indent="") {
    switch (gettype($var)) {
        case "string":
            return '"' . addcslashes($var, "\\\$\"\r\n\t\v\f") . '"';
        case "array":
            $indexed = array_keys($var) === range(0, count($var) - 1);
            $r = [];
            foreach ($var as $key => $value) {
                $r[] = "$indent    "
                     . ($indexed ? "" : var_export54($key) . " => ")
                     . var_export54($value, "$indent    ");
            }
            return "[\n" . implode(",\n", $r) . "\n" . $indent . "]";
        case "boolean":
            return $var ? "TRUE" : "FALSE";
        default:
            return var_export($var, TRUE);
    }
}

print var_export54(["B"=>1.2,"C"=>TRUE,"D"=>3,"E"=>[4,"\\text \"\$here\r\n\t",6,[7,8]]]);