HTML_AJAX
[ class tree: HTML_AJAX ] [ index: HTML_AJAX ] [ all elements ]

Source for file serialize.php.examples.php

Documentation is available at serialize.php.examples.php

  1. <script type="text/javascript" src="server.php?client=phpSerializer,util"></script>
  2. <?php
  3.  
  4. $examples = array(
  5.     '$foo = null;',
  6.     '$foo = true;',
  7.     '$foo = "foobar";',
  8.     '$foo = 337;',
  9.     '$foo = 99.99;',
  10.     '$foo = array("a" => 1, "b" => 2, 3);',
  11.     '$foo = array(1,2,array(1,2,3));',
  12.     'class Foo { var $foo; var $bar; }' 
  13.     . '$foo = new Foo; $foo->foo = "hello"; $foo->bar = array("world","universe");'
  14. );
  15.  
  16. echo '<h1><a name="pos">Positives</a> | <a href="#neg">Negatives</a></h1>';
  17. $c count($examples);
  18. for ($i = 0; $i $c$i++{
  19.     echo "<strong>PHP Code:</strong>\n<pre>$examples[$i]</pre>\n<strong>PHP value:</strong><pre>\n";
  20.     eval($examples[$i]);
  21.     var_dump($foo);
  22.     $sfoo serialize($foo);
  23.     echo "</pre>\n<strong>Serialized in PHP:</strong>\n<pre>"$sfoo"</pre>\n",
  24.          "<strong>Unserialized in JS:</strong>\n<pre>\n",
  25.          '<script type="text/javascript">',
  26.          'var jsr = new HTML_AJAX_Serialize_PHP();',
  27.          'var sfoo = unescape("'urlencode($sfoo)'"); var usfoo = jsr.unserialize(sfoo); if (jsr.error) {',
  28.          'document.write("Error: " + jsr.getError() + "\n"); } document.write(HTML_AJAX_Util.varDump(usfoo) + ',
  29.          '"</pre>\n<strong>Serialized in JS:</strong>\n<pre>" + jsr.serialize(usfoo));'"</script>\n</pre>\n<hr />\n\n";
  30. }
  31.  
  32. $bad_examples = array(
  33.     'x',
  34.     'x:1',
  35.     'N',
  36.     'Nx',
  37.     'b:f;',
  38.     'b:1',
  39.     'i:foo;',
  40.     'i:1',
  41.     'd:foo;',
  42.     'd:1.1.1;',
  43.     'd:1.1',
  44.     's:6:"foo";',
  45.     's:6:"foofoo"',
  46.     's:1:"foo";',   
  47.     's:0:""',
  48.     'a:3:{s:1:"aa";i:1;s:1:"b";i:2;i:0;i:3;}',
  49.     'a:4:{s:1:"a";i:1;s:1:"b";i:2;i:0;i:3;',
  50.     'a:3:{i:1;s:1:"b";i:2;i:0;i:3;}',
  51.     'a:3:{}',
  52.     'O:3:"Fooo":2:{s:3:"foo";s:5:"hello";s:3:"bar";a:2:{i:0;s:5:"world";i:1;s:8:"universe";}}',
  53.     'O:3:"Foo":3:{s:3:"foo";s:5:"hello";s:3:"bar";a:2:{i:0;s:5:"world";i:1;s:8:"universe";}}',
  54.     'O:3:"Foo":2:{s:5:"hello";s:3:"bar";a:2:{i:0;s:5:"world";i:1;s:8:"universe";}}',
  55.     'O:3:"Foo":2:{s:3:"foo";s:5:"hello";s:3:"bar";a:2:{i:0;s:5:"world";i:1;s:8:"universe";}',
  56.     'O:3:"Foo":2:{s:3:"foo";s:5:"hello";s:3:"bar";a:2:{i:0;s:5:"world";i:1;s:8:"universe"}}'
  57. );
  58.  
  59. echo '<h1><a href="#pos">Positives</a> | <a name="neg">Negatives</a></h1>';
  60. foreach ($bad_examples as $sfoo{
  61.     echo "</pre>\n<strong>Invalidly serialized:</strong>\n<pre>"$sfoo"</pre>\n",
  62.          "<strong>Unserialized in JS:</strong>\n<pre>\n",
  63.          '<script type="text/javascript">',
  64.          'var sfoo = unescape("'urlencode($sfoo)'"); var usfoo = jsr.unserialize(sfoo); if (jsr.error) {',
  65.          'document.write("Error: " + jsr.getError() + "\n"); } document.write(HTML_AJAX_Util.varDump(usfoo));',
  66.          "</script>\n</pre>\n<hr />\n\n";
  67. }
  68.  
  69.  
  70. ?>

Documentation generated on Mon, 11 Mar 2019 14:05:31 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.