kahlan\util\Text::dump PHP Method

dump() public static method

Dump some scalar data using a string representation
public static dump ( mixed $value, $quote = '"' ) : string
$value mixed The scalar data to dump
return string The dumped string.
    public static function dump($value, $quote = '"')
    {
        if (is_bool($value)) {
            return $value ? 'true' : 'false';
        }
        if (is_null($value)) {
            return 'null';
        }
        if (!$quote || !is_string($value)) {
            return (string) $value;
        }
        if ($quote === '"') {
            return $quote . static::_dump($value) . $quote;
        }
        return $quote . addcslashes($value, $quote) . $quote;
    }

Usage Example

Example #1
0
        });
        it("dumps a string with double quote", function () {
            $dump = Text::dump('Hel"lo');
            $this->expect($dump)->toBe('"Hel\\"lo"');
        });
        it("dumps a string with simple quote", function () {
            $dump = Text::dump("Hel'lo", "'");
            $this->expect($dump)->toBe("'Hel\\'lo'");
        });
        it("expands escape sequences and escape special chars", function () {
            $dump = Text::dump(" \t \nHello   \r\n \v \f World\n\n");
            $this->expect($dump)->toBe("\" \\t \\nHello \\x07 \\x08 \\r\\n \\v \\f World\\n\\n\"");
        });
        it("expands an empty string as \"\"", function () {
            $dump = Text::dump('');
            $this->expect($dump)->toBe('""');
        });
        it("expands an zero string as 0", function () {
            $dump = Text::dump('2014');
            $this->expect($dump)->toBe('"2014"');
        });
        it("expands espcape special chars", function () {
            $dump = Text::dump('20$14');
            $this->expect($dump)->toBe('"20\\$14"');
            $dump = Text::dump('20"14');
            $this->expect($dump)->toBe('"20\\"14"');
            $dump = Text::dump('20\\14');
            $this->expect($dump)->toBe('"20\\\\14"');
        });
    });
});
All Usage Examples Of kahlan\util\Text::dump