Wrox Programmer Forums
Go Back   Wrox Programmer Forums > PHP/MySQL > Pro PHP
| Search | Today's Posts | Mark Forums Read
Pro PHP Advanced PHP coding discussions. Beginning-level questions will be redirected to the Beginning PHP forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Pro PHP section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 19th, 2008, 01:17 PM
Registered User
 
Join Date: Dec 2007
Location: , , .
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default XSLT php:function: call objects non static method

Hi,

as you all know it is possible to call php functions from inside a xslt template like this:

Code:
<xsl:value-of select="php:function('strtoupper', string(.) )" />
<xsl:value-of select="php:function('aClass::aStaticFunction', string(.))"/>
(Assumed registerPhpFunctions() is called and the php namespace is set)

My code uses the singleton pattern and therefore there is one instance of a certain object. The php application invokes its methods like this:
Code:
$GLOBALS['aSingleton']->aNonStaticFunction($param);
Question:
How can I call this method from inside the XSLT? Obviously this won't work:
Code:
<xsl:value-of select="php:function('$GLOBALS['aSingleton']->aNonStaticFunction', string(.) )" />
Thanks in advance
Best regards

 
Old June 6th, 2008, 05:39 PM
Friend of Wrox
Points: 894, Level: 11
Points: 894, Level: 11 Points: 894, Level: 11 Points: 894, Level: 11
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Sep 2005
Location: London, , United Kingdom.
Posts: 166
Thanks: 2
Thanked 33 Times in 33 Posts
Default

Hi,

I haven't done much with PHP XSL, but you can actually pass other arguments to the function other than the xsl bit.
The real problem with your code is that you can't pass arrays to the XSL functions, and the quotes are a right pain.

For the most part, you should be able to get round this by creating a simple global wrapper function which can call any other one. This can take the name of the global variable, the function name, and the argument[s]. At its most basic:

function CallGlobalFunction($objName, $funcName, $arg)
{
  return $GLOBALS[$objName]->$funcName($arg);
}

Your XSL can then call this when it needs an instance:

<xsl:value-of select="php:function('CallGlobalFunction', 'aSingleton', 'aNonStaticFunction', string(.))" />


Hope this Helps
Phil




Similar Threads
Thread Thread Starter Forum Replies Last Post
Calling a function on every method call Takashi321 General .NET 1 September 21st, 2007 09:33 AM
Using Strings to Call objects rpjamess1 Visual Basic 2005 Basics 2 June 1st, 2007 11:43 AM
How can I call COM+ objects on another computer jdmc C# 2 May 30th, 2006 05:24 AM
how to achieve static method in an interface? cfouquet C# 3 September 28th, 2004 08:59 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.