Page 1 of 1
overriding functions
Posted: Sat Nov 08, 2003 3:49 pm
by civax
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?
Posted: Sat Nov 08, 2003 4:42 pm
by Gen-ik
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
Code: Select all
<?php
function test($arg)
{
echo $arg."<br />";
}
require_once("profile_one.php");
require_once("profile_two.php");
?>
PROFILE_ONE.PHP
Code: Select all
<?php
test("stuff from profile one");
?>
PROFILE_TWO.PHP
Code: Select all
<?php
test("stuff from profile two");
?>
Posted: Sat Nov 08, 2003 5:40 pm
by McGruff
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.
Posted: Mon Nov 10, 2003 5:17 am
by JAM
I thougt I could mention create_function() alsothat lets you create temporary functions based on runtime information (if wanted).
However, this might consume memory on occasion depending on how many new functions are created.
Posted: Mon Nov 10, 2003 2:32 pm
by civax
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.