xref: /PHP-7.3/ext/xsl/tests/xslt011.phpt (revision b746e698)
1--TEST--
2Test 11: php:function Support
3--SKIPIF--
4<?php require_once dirname(__FILE__) .'/skipif.inc'; ?>
5--FILE--
6<?php
7print "Test 11: php:function Support\n";
8  Class foo {
9       function __construct() {}
10       function __toString() { return "not a DomNode object";}
11  }
12
13$dom = new domDocument();
14  $dom->load(dirname(__FILE__)."/xslt011.xsl");
15  $proc = new xsltprocessor;
16  $xsl = $proc->importStylesheet($dom);
17
18  $xml = new DomDocument();
19  $xml->load(dirname(__FILE__)."/xslt011.xml");
20  $proc->registerPHPFunctions();
21  print $proc->transformToXml($xml);
22
23  function foobar($id, $secondArg = "" ) {
24    if (is_array($id)) {
25        return $id[0]->value . " - " . $secondArg;
26    } else {
27        return $id . " - " . $secondArg;
28    }
29  }
30  function nodeSet($id = null) {
31      if ($id and is_array($id)) {
32          return $id[0];
33      } else {
34          $dom = new domdocument;
35          $dom->loadXML("<root>this is from an external DomDocument</root>");
36          return $dom->documentElement;
37      }
38  }
39  function nonDomNode() {
40    return  new foo();
41  }
42
43  class aClass {
44    static function aStaticFunction($id) {
45        return $id;
46    }
47  }
48--EXPECTF--
49Test 11: php:function Support
50
51Warning: XSLTProcessor::transformToXml(): A PHP Object cannot be converted to a XPath-string in %s on line 16
52<?xml version="1.0"?>
53foobar - secondArg
54foobar -
55this is from an external DomDocument
56from the Input Document
57static
58