]> granicus.if.org Git - php/commitdiff
- make static methods calls work from within xslt
authorChristian Stocker <chregu@php.net>
Tue, 20 Apr 2004 09:24:24 +0000 (09:24 +0000)
committerChristian Stocker <chregu@php.net>
Tue, 20 Apr 2004 09:24:24 +0000 (09:24 +0000)
- extended tests

ext/xsl/tests/xslt011.phpt
ext/xsl/tests/xslt011.xsl
ext/xsl/xsltprocessor.c

index 64504ef8e47870b0916dc231599ade4fd835669a..5f7865279e2ffddb4a1e06e3f6a9d6169ca4d5c3 100644 (file)
@@ -39,6 +39,13 @@ $dom = new domDocument();
   function nonDomNode() {
     return  new foo();
   }
+  
+  class aClass {
+    static function aStaticFunction($id) {
+        return $id;
+    }
+  }
+  
 --EXPECTF--
 Test 11: php:function Support
 
@@ -48,4 +55,5 @@ foobar - secondArg
 foobar - 
 this is from an external DomDocument
 from the Input Document
+static
 
index 55609bbeaa822fcabcafbe5d4b781d7e13906ac5..e1960e57d3beb4e162cabf00aa419a0c1a3e4115 100644 (file)
 <xsl:value-of select="php:function('nodeSet',/doc)/i"/>
 <xsl:text>
 </xsl:text>
+<xsl:value-of select="php:function('aClass::aStaticFunction','static')"/>
+<xsl:text>
+</xsl:text>
+
 <xsl:value-of select="php:function('nonDomNode')"/>
 </xsl:template>
 </xsl:stylesheet>
index 1f73b3c15a55d61dbe181e6ff6adc47333d34b01..10c7e668a316d44232b072383316945a04054e89 100644 (file)
@@ -142,7 +142,8 @@ static void xsl_ext_function_php(xmlXPathParserContextPtr ctxt, int nargs, int t
        zval handler;
        xmlXPathObjectPtr obj;
        char *str;
-
+       char *callable = NULL;
+       
        TSRMLS_FETCH();
 
        tctxt = xsltXPathGetTransformContext(ctxt);
@@ -243,29 +244,34 @@ static void xsl_ext_function_php(xmlXPathParserContextPtr ctxt, int nargs, int t
        fci.retval_ptr_ptr = &retval;
        fci.no_separation = 0;
        /*fci.function_handler_cache = &function_ptr;*/
-       
-       result = zend_call_function(&fci, NULL TSRMLS_CC);
-       if (result == FAILURE) {
-               if (Z_TYPE(handler) == IS_STRING) {
-                       php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to call handler %s()", Z_STRVAL_P(&handler));
-               } 
+       if (!zend_make_callable(&handler, &callable TSRMLS_CC)) {
+               php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to call handler %s()", callable);
+               efree(callable);
+               
        } else {
-               if (retval->type == IS_OBJECT && instanceof_function( Z_OBJCE_P(retval), dom_node_class_entry TSRMLS_CC)) {
-                       xmlNode *nodep;
-                       dom_object *obj;
-                       obj = (dom_object *)zend_object_store_get_object(retval TSRMLS_CC);
-                       nodep = dom_object_get_node(obj);
-                       valuePush(ctxt, xmlXPathNewNodeSet(nodep));
-               } else if (retval->type == IS_BOOL) {
-                       valuePush(ctxt, xmlXPathNewBoolean(retval->value.lval));
-               } else if (retval->type == IS_OBJECT) {
-                       php_error_docref(NULL TSRMLS_CC, E_WARNING, "A PHP Object can not be converted to a XPath-string");
-                       valuePush(ctxt, xmlXPathNewString(""));
+               result = zend_call_function(&fci, NULL TSRMLS_CC);
+               if (result == FAILURE) {
+                       if (Z_TYPE(handler) == IS_STRING) {
+                               php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to call handler %s()", Z_STRVAL_P(&handler));
+                       } 
                } else {
-                       convert_to_string_ex(&retval);
-                       valuePush(ctxt, xmlXPathNewString( Z_STRVAL_P(retval)));
+                       if (retval->type == IS_OBJECT && instanceof_function( Z_OBJCE_P(retval), dom_node_class_entry TSRMLS_CC)) {
+                               xmlNode *nodep;
+                               dom_object *obj;
+                               obj = (dom_object *)zend_object_store_get_object(retval TSRMLS_CC);
+                               nodep = dom_object_get_node(obj);
+                               valuePush(ctxt, xmlXPathNewNodeSet(nodep));
+                       } else if (retval->type == IS_BOOL) {
+                               valuePush(ctxt, xmlXPathNewBoolean(retval->value.lval));
+                       } else if (retval->type == IS_OBJECT) {
+                               php_error_docref(NULL TSRMLS_CC, E_WARNING, "A PHP Object can not be converted to a XPath-string");
+                               valuePush(ctxt, xmlXPathNewString(""));
+                       } else {
+                               convert_to_string_ex(&retval);
+                               valuePush(ctxt, xmlXPathNewString( Z_STRVAL_P(retval)));
+                       }
+                       zval_ptr_dtor(&retval);
                }
-               zval_ptr_dtor(&retval);
        }
        zval_dtor(&handler);
        for (i = 0; i < nargs - 1; i++) {