xref: /PHP-5.6/ext/xsl/tests/bug49634.phpt (revision 6408a1a5)
1--TEST--
2bug #49634 (Segfault throwing an exception in a XSL registered function)
3--SKIPIF--
4<?php
5extension_loaded("xsl") or die("skip need ext/xsl");
6?>
7--FILE--
8<?php
9
10$sXml = <<<XML
11<?xml version="1.0" encoding="UTF-8" ?>
12<root>
13	test
14</root>
15XML;
16
17$cDIR = __DIR__;
18$sXsl = <<<XSL
19<xsl:stylesheet version="1.0"
20                xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
21                xmlns:ext="http://php.net/xsl"
22                xsl:extension-element-prefixes="ext"
23                exclude-result-prefixes="ext">
24	<xsl:output encoding="UTF-8" indent="yes" method="xml" />
25	<xsl:template match="/">
26		<xsl:value-of select="ext:function('testFunction', document('$cDIR/bug49634.xml')/root)"/>
27	</xsl:template>
28</xsl:stylesheet>
29XSL;
30
31function testFunction($a)
32{
33		throw new Exception('Test exception.');
34}
35
36$domXml = new DOMDocument;
37$domXml->loadXML($sXml);
38$domXsl = new DOMDocument;
39$domXsl->loadXML($sXsl);
40
41for ($i = 0; $i < 10; $i++)
42{
43	$xsltProcessor = new XSLTProcessor();
44	$xsltProcessor->registerPHPFunctions(array('testFunction'));
45	$xsltProcessor->importStyleSheet($domXsl);
46	try {
47		@$xsltProcessor->transformToDoc($domXml);
48	} catch (Exception $e) {
49		echo $e,"\n";
50	}
51}
52?>
53===DONE===
54--EXPECTF--
55exception 'Exception' with message 'Test exception.' in %s:%d
56Stack trace:
57#0 [internal function]: testFunction(Array)
58#1 %s(%d): XSLTProcessor->transformToDoc(Object(DOMDocument))
59#2 {main}
60exception 'Exception' with message 'Test exception.' in %s:%d
61Stack trace:
62#0 [internal function]: testFunction(Array)
63#1 %s(%d): XSLTProcessor->transformToDoc(Object(DOMDocument))
64#2 {main}
65exception 'Exception' with message 'Test exception.' in %s:%d
66Stack trace:
67#0 [internal function]: testFunction(Array)
68#1 %s(%d): XSLTProcessor->transformToDoc(Object(DOMDocument))
69#2 {main}
70exception 'Exception' with message 'Test exception.' in %s:%d
71Stack trace:
72#0 [internal function]: testFunction(Array)
73#1 %s(%d): XSLTProcessor->transformToDoc(Object(DOMDocument))
74#2 {main}
75exception 'Exception' with message 'Test exception.' in %s:%d
76Stack trace:
77#0 [internal function]: testFunction(Array)
78#1 %s(%d): XSLTProcessor->transformToDoc(Object(DOMDocument))
79#2 {main}
80exception 'Exception' with message 'Test exception.' in %s:%d
81Stack trace:
82#0 [internal function]: testFunction(Array)
83#1 %s(%d): XSLTProcessor->transformToDoc(Object(DOMDocument))
84#2 {main}
85exception 'Exception' with message 'Test exception.' in %s:%d
86Stack trace:
87#0 [internal function]: testFunction(Array)
88#1 %s(%d): XSLTProcessor->transformToDoc(Object(DOMDocument))
89#2 {main}
90exception 'Exception' with message 'Test exception.' in %s:%d
91Stack trace:
92#0 [internal function]: testFunction(Array)
93#1 %s(%d): XSLTProcessor->transformToDoc(Object(DOMDocument))
94#2 {main}
95exception 'Exception' with message 'Test exception.' in %s:%d
96Stack trace:
97#0 [internal function]: testFunction(Array)
98#1 %s(%d): XSLTProcessor->transformToDoc(Object(DOMDocument))
99#2 {main}
100exception 'Exception' with message 'Test exception.' in %s:%d
101Stack trace:
102#0 [internal function]: testFunction(Array)
103#1 %s(%d): XSLTProcessor->transformToDoc(Object(DOMDocument))
104#2 {main}
105===DONE===
106