Search

Hi all,

I have a PHP function I need to access from an extension (custom extension). But am having trouble accessing the result.

So if I set up a test as follows, just to return the input:

function API_test($input){
    return 'Result: '.$input;
}

Using the following XSL in a page template (I've simplified the XPath for demonstration purposes, but the path I'm using works and returns the right result when used in a standard context):

<xsl:value-of xmlns:php="http://php.net/xsl" select="php:function('API_test', data/section/entry/field)"/>

The result I get is:

Array

Ok, I thought, let's serialize it in the PHP function, at which point I get the following result:

O:10:"DOMElement":0:{}

What gives?

I'm not sure what data/section/entry/field is expected to be (or $input respectively) but it's most likely a DOMElement. So either you parse it via xslt to get the needed string result or in PHP using DOMElement

Hey,

No DOM elements involved actually. The value in this case is an email address (i.e. the value of that XPath expression, which in this case is the same thing as $input as that's what's being passed into the function).

Part of the reason I was confused by the result is that it's just a string being passed into the function, or at least that's the intention.

I'm guessing that the PHP function isn't able to receive a raw XPath. So how do I parse it first, do you mean sticking the result into a parameter and passing the parameter into the function?

function API_test($input){
    return sprintf('Result: %s', (string)$input);
}

You also could store the value in an xslt variable and pass it to the function instead of the DOMElement.

Hm, that seems to be giving me the same results.

The code as you've provided returns Array and serialising it returns O:10:"DOMElement":0:{}

Same thing if I stick the XPath into an xsl:variable and pass that in instead.

I'm guessing there must be something else wrong here?

Aha, this worked in the end:

<xsl:value-of xmlns:php="http://php.net/xsl" select="php:function('API_test', string(data/section/entry/field))"/>

can you just do a var_dump($input); die; in your function. Just to sure what $input actually is.

ah, ok

Create an account or sign in to comment.

Symphony • Open Source XSLT CMS

Server Requirements

  • PHP 5.3-5.6 or 7.0-7.3
  • PHP's LibXML module, with the XSLT extension enabled (--with-xsl)
  • MySQL 5.5 or above
  • An Apache or Litespeed webserver
  • Apache's mod_rewrite module or equivalent

Compatible Hosts

Sign in

Login details