Beispiel #1
0
<?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
echo $personStr . "\n";
//{"name":"John","mail":(v0) => ({"author":"John","message":v0})}
echo \LJSON\LJSON::stringify($mail) . "\n";
//{"author":"John","message":"hello"}
Beispiel #2
0
 /**
  * @expectedException \Exception
  */
 public function testParseExceptionNotCompletedVariableCall()
 {
     LJSON::parse('(v0) => v0( ');
 }
Beispiel #3
0
<?php

require_once "../vendor/autoload.php";
/*
 * Client:
 */
$func = function () {
    echo "Hallo";
    return "World";
};
$ljsonString = \LJSON\LJSON::stringify($func);
//Hello
echo "\nsend to server -> " . $ljsonString . "\n";
//<br>
// send to server -> () => ("World")
//<br>
/*
 * Server:
 */
$functionFromClient = \LJSON\LJSON::parse($ljsonString);
echo $functionFromClient();
//World
/*
 * The full Result:
 */
$fullResult = 'Hallo
send to server -> () => ("World")
World';