Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > PHP/MySQL > Pro PHP
Password Reminder
| FAQ | Members List | Calendar | 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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
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


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

<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:
How can I call this method from inside the XSLT? Obviously this won't work:
<xsl:value-of select="php:function('$GLOBALS['aSingleton']->aNonStaticFunction', string(.) )" />
Thanks in advance
Best regards

Reply With Quote
  #2 (permalink)  
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


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
Reply With Quote

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

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

All times are GMT -4. The time now is 01:56 PM.

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