Closed qwe900 closed 7 years ago
where exactly did you get this example code?
From here : http://sabre.io/xml/reading/
changing from
function(Reader $reader) {
to
function(Sabre\Xml\Reader $reader) {
works
fixed that for you. feel free to provide improvements for the docs at the repos on https://github.com/fruux/sabre.io
thanks!
the changes will be live after @evert had a free minute to re-deploy the website.
Hi when i use the code from example within the xml provided i get this error `include 'vendor/autoload.php'; $xml = file_get_contents('1.xml'); $service = new Sabre\Xml\Service();
$service->elementMap = [ '{http://example.org/books}book' => function(Reader $reader) { return Sabre\Xml\Deserializer\keyValue($reader, 'http://example.org/books'); }, '{http://example.org/books}books' => function(Reader $reader) { return Sabre\Xml\Deserializer\repeatingElements($reader, '{http://example.org/books}book'); }, ];
$result = $service->parse($xml);`
Error :
Fatal error: Uncaught TypeError: Argument 1 passed to {closure}() must be an instance of Reader, instance of Sabre\Xml\Reader given in C:\xampp\htdocs\w\index.php:13 Stack trace: #0 [internal function]: {closure}(Object(Sabre\Xml\Reader)) #1 C:\xampp\htdocs\w\vendor\sabre\xml\lib\Reader.php(229): call_user_func(Object(Closure), Object(Sabre\Xml\Reader)) #2 C:\xampp\htdocs\w\vendor\sabre\xml\lib\Reader.php(71): Sabre\Xml\Reader->parseCurrentElement() #3 C:\xampp\htdocs\w\vendor\sabre\xml\lib\Service.php(112): Sabre\Xml\Reader->parse() #4 C:\xampp\htdocs\w\index.php(23): Sabre\Xml\Service->parse('<?xml version="...') #5 {main} thrown in C:\xampp\htdocs\w\index.php on line 13