Hi,
I've coded a script that scans sites based on profiles made by users and return results. Now, each profile has a function rewrite() that rewrites data according to the site.
I now try to scan multiple sites.
It all works well for the first site, then it throws Fatal error: Cannot redeclare rewrite() in ...
My question - How can I import each profile (php file) for temporary usage - if it is possible?
I'm also trying to think of alternative ways to have the rewrite function called. Or maybe a way to update the function content whenever a new profile is being called.
Any help?
overriding functions
Moderator: General Moderators
The error means that you are trying to include two or more functions with the same name into PHP.
Why not simply have the function in the main page without having to include it, and then in each profile just send any infomation to the the function.
Here's a basic example...
MAIN PHP PAGE
PROFILE_ONE.PHP
PROFILE_TWO.PHP
Why not simply have the function in the main page without having to include it, and then in each profile just send any infomation to the the function.
Here's a basic example...
MAIN PHP PAGE
Code: Select all
<?php
function test($arg)
{
echo $arg."<br />";
}
require_once("profile_one.php");
require_once("profile_two.php");
?>Code: Select all
<?php
test("stuff from profile one");
?>Code: Select all
<?php
test("stuff from profile two");
?>Extending an abstract, base class is a common technique to overide functions but I don't know if that's what your're looking for.
In the child, you'd define a function with the same name as the overidden method in the parent class. The parent method simply contains a die('method not implemented'); line to make sure it DOES get overidden.
A good source for OOP techniques is phppatterns.com.
In the child, you'd define a function with the same name as the overidden method in the parent class. The parent method simply contains a die('method not implemented'); line to make sure it DOES get overidden.
A good source for OOP techniques is phppatterns.com.
actually, to give more details, I'm trying to extend this script that I've wrote:
http://cfxweb.net/civax/code.htm#newsgrabber
the profiles of each site contains few string vars and 1 function.
I've just rewroe the script to handle scanning of SEVERAL sites in one go. Basically what I'm trying to do is get the news grabbing in a loop and each time giving it a new profile. The problem is that with the second import of a profile file I get the mentioned error.
I don't mind changing the profiles format. I just need to have it all the profile details in 1 file to ease up on users creating new profiles for themselves.
http://cfxweb.net/civax/code.htm#newsgrabber
the profiles of each site contains few string vars and 1 function.
I've just rewroe the script to handle scanning of SEVERAL sites in one go. Basically what I'm trying to do is get the news grabbing in a loop and each time giving it a new profile. The problem is that with the second import of a profile file I get the mentioned error.
I don't mind changing the profiles format. I just need to have it all the profile details in 1 file to ease up on users creating new profiles for themselves.