Fiji Web Design
Welcome, Guest
Please Login or Register.    Lost Password?
Re:using function library (1 viewing) (1) Guest
Go to bottom Post Reply Favoured: 0
TOPIC: Re:using function library
#1115
deejay (User)
Fresh Boarder
Posts: 2
graphgraph
User Offline Click here to see the profile of this user
using function library 2 Years, 1 Month ago Karma: 0  
Hi

I'm trying to squeeze an existing site into Joomla. So this component looks ideal.

Only I seem to be having a snag calling functions

How would I for example use this function

function helloWorld() {
echo 'hello world!';
}


in a page. at the moment it seems to break the site.

Thank you for any help in advance.
 
Report to moderator   Logged Logged  
  The administrator has disabled public write access.
#1116
admin (Admin)
Admin
Posts: 475
graph
User Online Now Click here to see the profile of this user
Re:using function library 2 Years, 1 Month ago Karma: 10  
Functions are global, so 'helloWorld' would always be called as: helloWorld();

Make sure you have the correct file paths. It is likely the file with the function declaration is not being include()'ed.

Try turning on error reporting to full.

ini_set('error_reporting ', E_ALL);
ini_set('display_errors', '1');
 
Report to moderator   Logged Logged  
  The administrator has disabled public write access.
#1127
deejay (User)
Fresh Boarder
Posts: 2
graphgraph
User Offline Click here to see the profile of this user
Re:using function library 2 Years, 1 Month ago Karma: 0  
Thanks for the reply.


I can get that to work now, unfortunatley the site has too big a function library to go through all functions and make everything global.

Thanks anyway
 
Report to moderator   Logged Logged  
  The administrator has disabled public write access.
#1128
admin (Admin)
Admin
Posts: 475
graph
User Online Now Click here to see the profile of this user
Re:using function library 2 Years, 1 Month ago Karma: 10  
The PHP Component runs inside a function. So it runs in a local scope.

Functions are always global (they have no scope). Even if a function is declared in another function, it still becomes global. Same goes for classes and their methods. Only variable references have scope and thus would be effected by the com_php component.

In other words, if you couldn't call a function, it means it has not been declared. So likely the file paths you are using are not correct.

Since variables have scope, then variables declared outside com_php will have to be imported with the 'global' keyword. Joomla has JFactory for retrieving singletons in a way that is similar to using 'global' but without the 'global namespace pollution' that has gone out of style.
 
Report to moderator   Logged Logged  
  The administrator has disabled public write access.
#1129
admin (Admin)
Admin
Posts: 475
graph
User Online Now Click here to see the profile of this user
Re:using function library 2 Years, 1 Month ago Karma: 10  
After reading my response, I don't think it was quite clear. To answer you last post directly, you do not have to go through all the functions and make them global. You just need to make sure you have the correct paths to include those files those functions are declared in. You also need to make sure the variables declared outside the PHP component are imported into the local scope.
 
Report to moderator   Logged Logged  
  The administrator has disabled public write access.
Go to top Post Reply
Powered by FireBoardget the latest posts directly to your desktop

Joomla Downloads

DownloadsDownload our free Joomla! Components, Modules and Plugins.