1--TEST-- 2setParameter exceptions test 3--EXTENSIONS-- 4xsl 5--FILE-- 6<?php 7 8function test(array $options) { 9 $xml = new DOMDocument; 10 $xml->loadXML('<X/>'); 11 12 $xsl = new DOMDocument; 13 $xsl->loadXML('<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"><xsl:output method="text"/><xsl:param name="foo"/><xsl:template match="/"><xsl:value-of select="$foo"/></xsl:template></xsl:stylesheet>'); 14 15 $xslt = new XSLTProcessor; 16 $xslt->importStylesheet($xsl); 17 $xslt->setParameter('', $options); 18 19 echo $xslt->transformToXml($xml), "\n"; 20} 21 22echo "--- Invalid key ---\n"; 23 24try { 25 test([ 26 12345 => "foo" 27 ]); 28} catch (TypeError $e) { 29 echo $e->getMessage(), "\n"; 30} 31 32echo "--- Valid key and value, but special cases ---\n"; 33 34test([ 35 "foo" => null, 36]); 37 38test([ 39 "foo" => true, 40]); 41 42echo "--- Exception from __toString should abort execution ---\n"; 43 44class MyStringable { 45 public function __toString(): string { 46 throw new Exception("exception!"); 47 } 48} 49 50try { 51 test([ 52 "foo" => new MyStringable, 53 ]); 54} catch (Throwable $e) { 55 echo $e->getMessage(), "\n"; 56} 57 58echo "--- Exception from warning should abort execution ---\n"; 59 60set_error_handler(function($errno, $errstr) { 61 throw new Exception($errstr); 62}, E_WARNING); 63 64try { 65 test([ 66 "foo" => [], 67 "foo2" => [], 68 ]); 69} catch (Throwable $e) { 70 echo $e->getMessage(), "\n"; 71} 72 73set_error_handler(null, E_WARNING); 74 75echo "--- Warning may continue execution ---\n"; 76 77try { 78 test([ 79 "foo" => [], 80 "foo2" => [], 81 ]); 82} catch (Throwable $e) { 83 echo $e->getMessage(), "\n"; 84} 85 86?> 87--EXPECTF-- 88--- Invalid key --- 89XSLTProcessor::setParameter(): Argument #2 ($name) must contain only string keys 90--- Valid key and value, but special cases --- 91 921 93--- Exception from __toString should abort execution --- 94exception! 95--- Exception from warning should abort execution --- 96Array to string conversion 97--- Warning may continue execution --- 98 99Warning: Array to string conversion in %s on line %d 100 101Warning: Array to string conversion in %s on line %d 102Array 103