sabre-io / xml

sabre/xml is an XML library that you may not hate.
http://sabre.io/xml/
BSD 3-Clause "New" or "Revised" License
516 stars 77 forks source link

Example code error #113

Closed qwe900 closed 7 years ago

qwe900 commented 7 years ago

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

staabm commented 7 years ago

where exactly did you get this example code?

qwe900 commented 7 years ago

From here : http://sabre.io/xml/reading/

qwe900 commented 7 years ago

changing from function(Reader $reader) { to function(Sabre\Xml\Reader $reader) { works

staabm commented 7 years ago

fixed that for you. feel free to provide improvements for the docs at the repos on https://github.com/fruux/sabre.io

thanks!

staabm commented 7 years ago

the changes will be live after @evert had a free minute to re-deploy the website.