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