Subversion-Projekte lars-tiefland.php_share

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
1 lars 1
<?PHP
2
/**
3
 * This is just a basic example that shows
4
 * how objects can be serialized so they can
5
 * be fully restored later.
6
 *
7
 * @author Stephan Schmidt <schst@php.net>
8
 */
9
 
10
/**
11
 * Example class that implements __sleep()
12
 *
13
 * @package    XML_Serializer
14
 * @subpackage Examples
15
 */
16
class MyClass
17
{
18
    var $foo = 'This is foo.';
19
    var $bar = 'This is bar.';
20
 
21
    function __sleep()
22
    {
23
        return array('foo');
24
    }
25
}
26
 
27
error_reporting(E_ALL);
28
 
29
/**
30
 * Load XML_Serializer
31
 */
32
require_once 'XML/Serializer.php';
33
 
34
 
35
// this is just to get a nested object
36
$pearError = PEAR::raiseError('This is just an error object',123);
37
 
38
$options = array(
39
                    XML_SERIALIZER_OPTION_INDENT      => '    ',
40
                    XML_SERIALIZER_OPTION_LINEBREAKS  => "\n",
41
                    XML_SERIALIZER_OPTION_DEFAULT_TAG => 'unnamedItem',
42
                    XML_SERIALIZER_OPTION_TYPEHINTS   => true
43
                );
44
 
45
$foo = new stdClass();
46
$foo->value = "My value";
47
$foo->error = $pearError;
48
$foo->xml   = "cool";
49
 
50
$foo->obj    = new MyClass();
51
$foo->arr   = array();
52
$foo->zero  = 0;
53
 
54
 
55
$serializer = &new XML_Serializer($options);
56
 
57
$result = $serializer->serialize($foo);
58
 
59
if( $result === true ) {
60
    $xml = $serializer->getSerializedData();
61
}
62
 
63
echo '<pre>';
64
echo htmlspecialchars($xml);
65
echo '</pre>';
66
?>