xref: /PHP-8.0/ext/xsl/tests/bug49634.phpt (revision f8d79582)
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--EXPECTF--
54Exception: Test exception. in %s:%d
55Stack trace:
56#0 [internal function]: testFunction(Array)
57#1 %s(%d): XSLTProcessor->transformToDoc(Object(DOMDocument))
58#2 {main}
59Exception: Test exception. in %s:%d
60Stack trace:
61#0 [internal function]: testFunction(Array)
62#1 %s(%d): XSLTProcessor->transformToDoc(Object(DOMDocument))
63#2 {main}
64Exception: Test exception. in %s:%d
65Stack trace:
66#0 [internal function]: testFunction(Array)
67#1 %s(%d): XSLTProcessor->transformToDoc(Object(DOMDocument))
68#2 {main}
69Exception: Test exception. in %s:%d
70Stack trace:
71#0 [internal function]: testFunction(Array)
72#1 %s(%d): XSLTProcessor->transformToDoc(Object(DOMDocument))
73#2 {main}
74Exception: Test exception. in %s:%d
75Stack trace:
76#0 [internal function]: testFunction(Array)
77#1 %s(%d): XSLTProcessor->transformToDoc(Object(DOMDocument))
78#2 {main}
79Exception: Test exception. in %s:%d
80Stack trace:
81#0 [internal function]: testFunction(Array)
82#1 %s(%d): XSLTProcessor->transformToDoc(Object(DOMDocument))
83#2 {main}
84Exception: Test exception. in %s:%d
85Stack trace:
86#0 [internal function]: testFunction(Array)
87#1 %s(%d): XSLTProcessor->transformToDoc(Object(DOMDocument))
88#2 {main}
89Exception: Test exception. in %s:%d
90Stack trace:
91#0 [internal function]: testFunction(Array)
92#1 %s(%d): XSLTProcessor->transformToDoc(Object(DOMDocument))
93#2 {main}
94Exception: Test exception. in %s:%d
95Stack trace:
96#0 [internal function]: testFunction(Array)
97#1 %s(%d): XSLTProcessor->transformToDoc(Object(DOMDocument))
98#2 {main}
99Exception: Test exception. in %s:%d
100Stack trace:
101#0 [internal function]: testFunction(Array)
102#1 %s(%d): XSLTProcessor->transformToDoc(Object(DOMDocument))
103#2 {main}
104