Sabre/XML Reader: Stripping the XML namespaces not working in PHP 7

435 views
Skip to first unread message

dandy.w...@gmail.com

unread,
Dec 31, 2016, 12:16:10 PM12/31/16
to SabreDAV Discussion
Hi there,

first of all, thank you for developing and releasing sabre/xml. I really think its an excellent XML parser.

I just installed the latest Sabre/XML version (2.0.0) using Compooser on my PHP 7.0.4 server and i am trying your basic READING examples as on http://sabre.io/xml/reading/. The first part, including the chapter "Key-Value XML structures", work flawlessly.

However, the chapter "Stripping the XML namespaces" does not work anymore.

My php file looks as follows (basically a copy & past from http://sabre.io/xml/reading/):

<?php

define
("ROOT",$_SERVER["DOCUMENT_ROOT"]);
define
("DATA",ROOT."/data/");

include
(ROOT.'/vendor/autoload.php');

$file
= DATA.'/books.xml';

$xml
= file_get_contents($file);

$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');
   
}
];

print_r
($service->parse($xml));

?>


This gives me the following error:

 
Fatal error: Uncaught TypeError: Argument 1 passed to {closure}() must be an instance of Reader, instance of Sabre\Xml\Reader given in /home/he052rz5/www/home/data/sabretest.php:14 Stack trace: #0 [internal function]: {closure}(Object(Sabre\Xml\Reader)) #1 /home/he052rz5/www/home/vendor/sabre/xml/lib/Reader.php(229): call_user_func(Object(Closure), Object(Sabre\Xml\Reader)) #2 /home/he052rz5/www/home/vendor/sabre/xml/lib/Reader.php(161): Sabre\Xml\Reader->parseCurrentElement() #3 /home/he052rz5/www/home/vendor/sabre/xml/lib/Element/Base.php(82): Sabre\Xml\Reader->parseInnerTree() #4 [internal function]: Sabre\Xml\Element\Base::xmlDeserialize(Object(Sabre\Xml\Reader)) #5 /home/he052rz5/www/home/vendor/sabre/xml/lib/Reader.php(229): call_user_func(Array, Object(Sabre\Xml\Reader)) #6 /home/he052rz5/www/home/vendor/sabre/xml/lib/Reader.php(71): Sabre\Xml\Reader->parseCurrentElement() #7 /home/he052rz5/www/home/vendor/sabre/xml/lib/Service.php(112): Sabre\Xml\Reader->parse() #8 /home/he052rz5/www/home/data/sabretest.php(19): S in /home/he052rz5/www/home/data/sabretest.php on line 14



I thought it may be related to PHP 7, because I have found a similar error (albeit from a differ application) here: https://wordpress.org/support/topic/php-7-related-error/

Thank you very much your help in advance.

Christoph

Evert Pot

unread,
Jan 2, 2017, 1:33:36 PM1/2/17
to SabreDAV Discussion
Hi Dandy,
There was an error in the documentation. Your file either needs to start with "use Sabre\Xml\Reader" or instead of the "Reader" keyword further down, it should have said "\Sabre\Xml\Reader". Alternatively, you can also remove the 'Reader' keyword entirely to fix it.

The docs should now be fixed too.

Evert
Message has been deleted

dandy.w...@gmail.com

unread,
Jan 3, 2017, 3:00:21 PM1/3/17
to SabreDAV Discussion
Hi Evert,

thank you for your answer and quick solution. I can confirm it's working now. Ta!

Fyi, I found another typo in the documentation, one ":" is missing between "Author" and "class" on http://sabre.io/xml/valueobjects/ :

Value Objects - Setup:

IS


$service
->mapValueObject('{http://www.w3.org/2005/Atom}author', Author:class);



SHOULD BE


$service
->mapValueObject('{http://www.w3.org/2005/Atom}author', Author::class);



Hope that helps to polish your splendid documentation.

Christoph

Evert Pot

unread,
Jan 3, 2017, 6:35:46 PM1/3/17
to SabreDAV Discussion
Thanks! This is fixed
Reply all
Reply to author
Forward
0 new messages