Script URL:
Version of script: 1.7
Hosting company: none
URL of phpinfo.php:
URL of session_test.php:
What terms did you try when SEARCHING for a solution: redeclare functons
Write your message below:
Hi,
I'm basically integrating linkman 1.7 into my wordpress theme. However, I don't have much problem with that. What I would like to highlight is regarding settings.php
inside settings.php, I noticed that there are 2 functions. If I've 2 scripts that decided to require 'settings.php'; I would obtain an error because I've declared the functions twice. Meanwhile, if I had it require_once 'settings.php'; it would be possible, but somehow, $settings was not set with values. I don't know why though.
so I was wondering, if those two functions should belong inside settings.php? Or, should it be included as another file in addlink.php and other files that requires this function.
Or, is there another solution to this problem?
Redeclare functions
The solution is to rename "setting.php" to "setting2.php" and all instances of "setting.php" within the script code (in all files) to "setting2.php".
If you do this for LinkMan or the other script doesn't matter, whichever is less work.
If you do this for LinkMan or the other script doesn't matter, whichever is less work.
Klemen, creator of HESK and PHPJunkyardWas this helpful? You can buy me a drink here 
You should follow me on Twitter here
Help desk software | Cloud help desk | Guestbook | Link manager | Click counter | more PHP Scripts ...
Also browse for php hosting companies, read php books, find php resources and use webmaster tools


Help desk software | Cloud help desk | Guestbook | Link manager | Click counter | more PHP Scripts ...
Also browse for php hosting companies, read php books, find php resources and use webmaster tools
Sorry, I was thinking about something and writing about something else. The function name needs to be renamed.
Don't just check if the function exists, because the LinkMan function, that in your case has the same name as some other function, most likely doesn't give the same results.
Don't just check if the function exists, because the LinkMan function, that in your case has the same name as some other function, most likely doesn't give the same results.
Klemen, creator of HESK and PHPJunkyardWas this helpful? You can buy me a drink here 
You should follow me on Twitter here
Help desk software | Cloud help desk | Guestbook | Link manager | Click counter | more PHP Scripts ...
Also browse for php hosting companies, read php books, find php resources and use webmaster tools


Help desk software | Cloud help desk | Guestbook | Link manager | Click counter | more PHP Scripts ...
Also browse for php hosting companies, read php books, find php resources and use webmaster tools
actually, I think you have got the wrong idea. On runtime, I don't think it's possible to rename the functions.
I had no choice but use a function_exists() check. The reason was simply, because if I use require_once, I would obtain errors, this is due to $settings not loaded. This happens when I have 2 separate scripts running at the same time, and uses require 'settings.php';.
The 2 separate scripts would call settings.php twice, resulting a redeclare of functions. Unless, there is another workaround to declare $settings. Because, from what I see, $settings seems to cleared up after the 1st script uses it, making $settings to be nulled.
Anyway, I found that it has to be a problem with the scope of the $settings variable.
My suggestion was, in future, couldn't those functions declared in settings.php be included as another function file? That would simply allow integration easily.
Thanks again.
I had no choice but use a function_exists() check. The reason was simply, because if I use require_once, I would obtain errors, this is due to $settings not loaded. This happens when I have 2 separate scripts running at the same time, and uses require 'settings.php';.
The 2 separate scripts would call settings.php twice, resulting a redeclare of functions. Unless, there is another workaround to declare $settings. Because, from what I see, $settings seems to cleared up after the 1st script uses it, making $settings to be nulled.
Anyway, I found that it has to be a problem with the scope of the $settings variable.
My suggestion was, in future, couldn't those functions declared in settings.php be included as another function file? That would simply allow integration easily.
Thanks again.
Wait, are you using two different scripts (each with it's own settings.php file) or are you using two copies of LinkMan? Because it makes all the difference. The solution with function_exist would only work properly in the latter case, my solution (renaming function) assumed that you have two completely different scripts each using it's own settings.php file.
Klemen, creator of HESK and PHPJunkyardWas this helpful? You can buy me a drink here 
You should follow me on Twitter here
Help desk software | Cloud help desk | Guestbook | Link manager | Click counter | more PHP Scripts ...
Also browse for php hosting companies, read php books, find php resources and use webmaster tools


Help desk software | Cloud help desk | Guestbook | Link manager | Click counter | more PHP Scripts ...
Also browse for php hosting companies, read php books, find php resources and use webmaster tools
Hi,
Take it this way, since links.php displays generates the form, I took out the display and left the generate part in links.php. The second script I was talking about was display.php.
I've that so that, when I use access my home page, I only need display.php. When I access the link-exchange page, I need both display.php and links.php.
display.php requires settings.php, so does links.php. Therefore, it is necessary for me to only load settings.php once. If I load settings.php twice, there will be a redeclare error.
In short, I think I'm using two different scripts (one generate and parse the form and the other displays), both loads the very same settings.php. Focing my script to load another settings.php would mean that the script is no longer dynamic.
------
Actually, I found out my problem. require_once works just fine, however, the wordpress structure is in such a way:
Inside index.php
Inside call_function1()
Inside call_function2()
Inside links.php
Inside display.php
If you get the idea, I think $settings was loaded as a local scope in call_function1() and call_function2(). So, $settings was not possible to be accessed in call_function2(). Instead, since it doesn't matter where you declare a function as it is accessible anywhere in the script, the script will declare the function twice.
Take it this way, since links.php displays generates the form, I took out the display and left the generate part in links.php. The second script I was talking about was display.php.
I've that so that, when I use access my home page, I only need display.php. When I access the link-exchange page, I need both display.php and links.php.
display.php requires settings.php, so does links.php. Therefore, it is necessary for me to only load settings.php once. If I load settings.php twice, there will be a redeclare error.
In short, I think I'm using two different scripts (one generate and parse the form and the other displays), both loads the very same settings.php. Focing my script to load another settings.php would mean that the script is no longer dynamic.
------
Actually, I found out my problem. require_once works just fine, however, the wordpress structure is in such a way:
Inside index.php
Code: Select all
call_function1();
call_function2();
Code: Select all
require 'links.php';
Code: Select all
require 'display.php';
Code: Select all
require_once 'settings.php';
Code: Select all
require_once 'settings.php';
I think I see what your problem was - you should call the settings file ONCE within the entire file (at the beginning) and then declare $settings as global within functions.
require settings.php
function one()
{
global $settings;
/* the rest of the code... */
}
function two()
{
global $settings;
/* the rest of the code... */
}
If you just include files within functions without declaring globals the $settings of course won't be available outside that function.
require settings.php
function one()
{
global $settings;
/* the rest of the code... */
}
function two()
{
global $settings;
/* the rest of the code... */
}
If you just include files within functions without declaring globals the $settings of course won't be available outside that function.
Klemen, creator of HESK and PHPJunkyardWas this helpful? You can buy me a drink here 
You should follow me on Twitter here
Help desk software | Cloud help desk | Guestbook | Link manager | Click counter | more PHP Scripts ...
Also browse for php hosting companies, read php books, find php resources and use webmaster tools


Help desk software | Cloud help desk | Guestbook | Link manager | Click counter | more PHP Scripts ...
Also browse for php hosting companies, read php books, find php resources and use webmaster tools