ljson / ljson
This package is abandoned and no longer maintained.
No replacement package was suggested.
JSON extended with pure functions. in PHP
v0.3.1
2016-07-29 20:36 UTC
Requires
- php: >=5.4.0
Requires (Dev)
- codeclimate/php-test-reporter: dev-master
- phpunit/phpunit: 4.8.*
- sebastian/phpcpd: *
- squizlabs/php_codesniffer: *
This package is auto-updated.
Last update: 2021-12-29 02:33:53 UTC
README
LJSON
LJSON is a drop-in replacement for JSON which also allows you to parse and stringify pure functions and their contents. There are good security reasons for functions to be out of the JSON specs, but most of those are only significant when you allow arbitrary, side-effective programs. With pure functions, one is able to interchange code while still being as safe as with regular JSON.
note:
this is a port of LJSON for JavaScript originaly from MaiaVictor
<?php require_once "vendor/autoload.php"; // A random object with a pure function inside. $person = [ "name" => "John", "mail" => function ($msg) { return [ "author" => "John", "message" => $msg, ]; }, ]; $personStr = \LJSON\LJSON::stringify($person); $personVal = \LJSON\LJSON::parse($personStr); $mailFunction = $personVal->mail; $mail = $mailFunction("hello");// would crash with json_encode echo $personStr . "\n"; echo \LJSON\LJSON::stringify($mail) . "\n";
output:
{"name":"John","mail":(v0) => ({"author":"John","message":v0})} {"author":"John","message":"hello"}
More info:
Installing
composer require ljson/ljson