Skip to content

Commit 65bc57a

Browse files
committed
- make static methods calls work from within xslt
- extended tests
1 parent e9c3ac0 commit 65bc57a

File tree

3 files changed

+39
-21
lines changed

3 files changed

+39
-21
lines changed

ext/xsl/tests/xslt011.phpt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,13 @@ $dom = new domDocument();
3939
function nonDomNode() {
4040
return new foo();
4141
}
42+
43+
class aClass {
44+
static function aStaticFunction($id) {
45+
return $id;
46+
}
47+
}
48+
4249
--EXPECTF--
4350
Test 11: php:function Support
4451

@@ -48,4 +55,5 @@ foobar - secondArg
4855
foobar -
4956
this is from an external DomDocument
5057
from the Input Document
58+
static
5159

ext/xsl/tests/xslt011.xsl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@
1616
<xsl:value-of select="php:function('nodeSet',/doc)/i"/>
1717
<xsl:text>
1818
</xsl:text>
19+
<xsl:value-of select="php:function('aClass::aStaticFunction','static')"/>
20+
<xsl:text>
21+
</xsl:text>
22+
1923
<xsl:value-of select="php:function('nonDomNode')"/>
2024
</xsl:template>
2125
</xsl:stylesheet>

ext/xsl/xsltprocessor.c

Lines changed: 27 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,8 @@ static void xsl_ext_function_php(xmlXPathParserContextPtr ctxt, int nargs, int t
142142
zval handler;
143143
xmlXPathObjectPtr obj;
144144
char *str;
145-
145+
char *callable = NULL;
146+
146147
TSRMLS_FETCH();
147148

148149
tctxt = xsltXPathGetTransformContext(ctxt);
@@ -243,29 +244,34 @@ static void xsl_ext_function_php(xmlXPathParserContextPtr ctxt, int nargs, int t
243244
fci.retval_ptr_ptr = &retval;
244245
fci.no_separation = 0;
245246
/*fci.function_handler_cache = &function_ptr;*/
246-
247-
result = zend_call_function(&fci, NULL TSRMLS_CC);
248-
if (result == FAILURE) {
249-
if (Z_TYPE(handler) == IS_STRING) {
250-
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to call handler %s()", Z_STRVAL_P(&handler));
251-
}
247+
if (!zend_make_callable(&handler, &callable TSRMLS_CC)) {
248+
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to call handler %s()", callable);
249+
efree(callable);
250+
252251
} else {
253-
if (retval->type == IS_OBJECT && instanceof_function( Z_OBJCE_P(retval), dom_node_class_entry TSRMLS_CC)) {
254-
xmlNode *nodep;
255-
dom_object *obj;
256-
obj = (dom_object *)zend_object_store_get_object(retval TSRMLS_CC);
257-
nodep = dom_object_get_node(obj);
258-
valuePush(ctxt, xmlXPathNewNodeSet(nodep));
259-
} else if (retval->type == IS_BOOL) {
260-
valuePush(ctxt, xmlXPathNewBoolean(retval->value.lval));
261-
} else if (retval->type == IS_OBJECT) {
262-
php_error_docref(NULL TSRMLS_CC, E_WARNING, "A PHP Object can not be converted to a XPath-string");
263-
valuePush(ctxt, xmlXPathNewString(""));
252+
result = zend_call_function(&fci, NULL TSRMLS_CC);
253+
if (result == FAILURE) {
254+
if (Z_TYPE(handler) == IS_STRING) {
255+
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to call handler %s()", Z_STRVAL_P(&handler));
256+
}
264257
} else {
265-
convert_to_string_ex(&retval);
266-
valuePush(ctxt, xmlXPathNewString( Z_STRVAL_P(retval)));
258+
if (retval->type == IS_OBJECT && instanceof_function( Z_OBJCE_P(retval), dom_node_class_entry TSRMLS_CC)) {
259+
xmlNode *nodep;
260+
dom_object *obj;
261+
obj = (dom_object *)zend_object_store_get_object(retval TSRMLS_CC);
262+
nodep = dom_object_get_node(obj);
263+
valuePush(ctxt, xmlXPathNewNodeSet(nodep));
264+
} else if (retval->type == IS_BOOL) {
265+
valuePush(ctxt, xmlXPathNewBoolean(retval->value.lval));
266+
} else if (retval->type == IS_OBJECT) {
267+
php_error_docref(NULL TSRMLS_CC, E_WARNING, "A PHP Object can not be converted to a XPath-string");
268+
valuePush(ctxt, xmlXPathNewString(""));
269+
} else {
270+
convert_to_string_ex(&retval);
271+
valuePush(ctxt, xmlXPathNewString( Z_STRVAL_P(retval)));
272+
}
273+
zval_ptr_dtor(&retval);
267274
}
268-
zval_ptr_dtor(&retval);
269275
}
270276
zval_dtor(&handler);
271277
for (i = 0; i < nargs - 1; i++) {

0 commit comments

Comments
 (0)