473,542 Members | 14,181 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

undefining functions

I have a master-script that runs for every site I make, and it has a standard
set of functions, but sometimes I would want to override that function for a
particular site, but if I redefine it for that site, PHP will complain about
overriding functions. Since that's a good warning, I wouldn't want to remove
it, but I would want to "undefine" a function before defining it again.

like: function_undefine("drawbox");

Or something like that.

Anyone got any suggestions?

--
Sandman[.net]
Jul 17 '05 #1
10 8224

you don't want to define, undefine and redefine functions or
do you have cpu cycles to waste?

split your functions.inc into modular entities that you can
load on request. load the site-specific things at the end.

request_once('func1.inc');
request_once('func2.inc');
request_once('func3.inc');
request_once('spec1.inc');
request_once('spec2.inc');


Sandman wrote:
I have a master-script that runs for every site I make, and it has a standard
set of functions, but sometimes I would want to override that function for a
particular site, but if I redefine it for that site, PHP will complain about
overriding functions. Since that's a good warning, I wouldn't want to remove
it, but I would want to "undefine" a function before defining it again.

like: function_undefine("drawbox");

Or something like that.

Anyone got any suggestions?


Jul 17 '05 #2
Sandman wrote:
Anyone got any suggestions?


<?php
class Master {
function func1() { echo 'func1'; return true; }
function func2() { echo 'func1'; return true; }
}
class Site_X {
function func1() { echo 'X1'; return true; }
function func2() { echo 'X1'; return true; }
}

if (Master::func1()) Site_X::func2();
?>
--
USENET would be a better place if everybody read: : mail address :
http://www.catb.org/~esr/faqs/smart-questions.html : is valid for :
http://www.netmeister.org/news/learn2quote2.html : "text/plain" :
http://www.expita.com/nomime.html : to 10K bytes :
Jul 17 '05 #3
"Sandman" <mr@sandman.net> wrote in message
news:mr**********************@news.fu-berlin.de...
I have a master-script that runs for every site I make, and it has a standard set of functions, but sometimes I would want to override that function for a particular site, but if I redefine it for that site, PHP will complain about overriding functions. Since that's a good warning, I wouldn't want to remove it, but I would want to "undefine" a function before defining it again.

like: function_undefine("drawbox");

Or something like that.

Anyone got any suggestions?


If your _sure_ this is what you want (bearing in mind the overhead involved
in parsing the
master-script functions even though they are not used), look into variable
functions.

I believe this is possible (correct me if i'm wrong)...

in master-script:

function foo_default()
{
echo 'blah blah blah';
}
$foo = 'foo_default';
in custom sctipt:

function foo_redefined()
{
echo 'yada yada yada')
}
$foo = 'foo_redefined'; // overwrite variable with new function name.
to call the function:

$foo();
Jul 17 '05 #4
In article <c3**********@taliesin2.netcom.net.uk>,
"Mark Henning" <ma*******@btopenworld.com> wrote:
If your _sure_ this is what you want (bearing in mind the overhead involved
in parsing the master-script functions even though they are not used), look
into variable functions.

I believe this is possible (correct me if i'm wrong)...

in master-script:

function foo_default() {
echo 'blah blah blah';
}
$foo = 'foo_default';
in custom sctipt:

function foo_redefined() {
echo 'yada yada yada')
}
$foo = 'foo_redefined'; // overwrite variable with new function name.
to call the function:

$foo();


Aaah, ok - while that might work, that would mean I would have to edit all the
scripts that use function foo_default(). It's possible, but I'll see if any
other suggestions come around - thanks!

--
Sandman[.net]
Jul 17 '05 #5
In article <c3*************@ID-203069.news.uni-berlin.de>,
Pedro Graca <he****@hotpop.com> wrote:
Sandman wrote:
Anyone got any suggestions?


<?php
class Master {
function func1() { echo 'func1'; return true; }
function func2() { echo 'func1'; return true; }
}
class Site_X {
function func1() { echo 'X1'; return true; }
function func2() { echo 'X1'; return true; }
}

if (Master::func1()) Site_X::func2();
?>


I could use some commentary here.

After having executed the class Site_X for my site and Master in my initscript
- would func1() echo "X1"?

What does the if do?

--
Sandman[.net]
Jul 17 '05 #6
Sandman wrote:
In article <c3*************@ID-203069.news.uni-berlin.de>,
Pedro Graca <he****@hotpop.com> wrote:
Sandman wrote:
> Anyone got any suggestions?
<?php
class Master {
function func1() { echo 'func1'; return true; }
function func2() { echo 'func1'; return true; }
}
class Site_X {
function func1() { echo 'X1'; return true; }
function func2() { echo 'X1'; return true; }
}

if (Master::func1()) Site_X::func2();
?>


I could use some commentary here.

After having executed the class Site_X for my site and Master in my initscript
- would func1() echo "X1"?


No. With the script above, the function "func1" does not exist.
You can also define a func1 outside of any class and call it with
func1().
You cannot have two functions with the same name. The most similar thing
available is putting them inside /different/ classes ... of course after
that their names are "Class::name" instead of simply "name".
/* rewrite of above script */
<?php
function func1() { echo 'global func1'; }

class Site_X {
function func1() { echo 'Site_X func1'; }
}

class Site_Y {
function func1() { echo 'Site_Y func1 + ', func1(); }
}

func1(); // prints "global func1"
Site_X::func1(); // prints "Site_X func1"
Site_Y::func1(); // prints "Site_Y func1 + global func1"
?>


What does the if do?


That was just to show you a way to call the different functions.
--
USENET would be a better place if everybody read: : mail address :
http://www.catb.org/~esr/faqs/smart-questions.html : is valid for :
http://www.netmeister.org/news/learn2quote2.html : "text/plain" :
http://www.expita.com/nomime.html : to 10K bytes :
Jul 17 '05 #7


doesn't make sense to me either.
usually classes are handled in seperate files for flexibility.
what you do here just pushes the problem one level down the line.

if you have to check conditions on classe, you can as well
do conditional includes...


Pedro Graca wrote:
Sandman wrote:
In article <c3*************@ID-203069.news.uni-berlin.de>,
Pedro Graca <he****@hotpop.com> wrote:

Sandman wrote:

Anyone got any suggestions?

<?php
class Master {
function func1() { echo 'func1'; return true; }
function func2() { echo 'func1'; return true; }
}
class Site_X {
function func1() { echo 'X1'; return true; }
function func2() { echo 'X1'; return true; }
}

if (Master::func1()) Site_X::func2();
?>


I could use some commentary here.

After having executed the class Site_X for my site and Master in my initscript
- would func1() echo "X1"?

No. With the script above, the function "func1" does not exist.
You can also define a func1 outside of any class and call it with
func1().
You cannot have two functions with the same name. The most similar thing
available is putting them inside /different/ classes ... of course after
that their names are "Class::name" instead of simply "name".
/* rewrite of above script */
<?php
function func1() { echo 'global func1'; }

class Site_X {
function func1() { echo 'Site_X func1'; }
}

class Site_Y {
function func1() { echo 'Site_Y func1 + ', func1(); }
}

func1(); // prints "global func1"
Site_X::func1(); // prints "Site_X func1"
Site_Y::func1(); // prints "Site_Y func1 + global func1"
?>

What does the if do?

That was just to show you a way to call the different functions.


Jul 17 '05 #8
Sandman wrote:
I have a master-script that runs for every site I make, and it has a
standard set of functions, but sometimes I would want to override
that function for a particular site, but if I redefine it for that
site, PHP will complain about overriding functions. Since that's a
good warning, I wouldn't want to remove it, but I would want to
"undefine" a function before defining it again.

like: function_undefine("drawbox");

Or something like that.

Anyone got any suggestions?


One suggestion is to use objects. Specifically, you could turn your
"master-script" into a class, and then instantiate your sites as children of
the class, something like:

<? /* master-class.php */

class BigKahuna {

/* here go functions */

function OneBigFatMasterFunction() {
}

}

?>

<? /* the_site.php */

require_once("master-class.php");

class TheSite extends BigKahuna {

function TheSite() {
/* this is the constructor function, that gets executed every time
you
instantiate the class
*/
}

function OneBigFatMasterFunction() {
/* this overrides the function above */
}

}

?>

<? /* index.php for the site */

require_once('the_site.php');

$site = new TheSite();

?>

That's all, except that instead of calling the functions defined in the two
class the usual way, you call them as $this->OneBigFatMasterFunction().

Berislav


--
If the Internet is a Marx Brothers movie, and Web, e-mail, and IRC are
Groucho, Chico, and Harpo, then Usenet is Zeppo.
Jul 17 '05 #9
Allan Rydberg top-posted:
Pedro Graca wrote:
You cannot have two functions with the same name. The most similar thing
available is putting them inside /different/ classes ... of course after
that their names are "Class::name" instead of simply "name".
Just (mis)using classes as namespaces.
/* rewrite of above script */
<?php
function func1() { echo 'global func1'; }

class Site_X {
function func1() { echo 'Site_X func1'; }
}

class Site_Y {
function func1() { echo 'Site_Y func1 + ', func1(); }
}

func1(); // prints "global func1"
Site_X::func1(); // prints "Site_X func1"
Site_Y::func1(); // prints "Site_Y func1 + global func1"
?>
usually classes are handled in seperate files for flexibility.
OK, doesn't matter if they're in different files.
what you do here just pushes the problem one level down the line.

if you have to check conditions on classe, you can as well
do conditional includes...


The OP wanted to 'undefine' a function. As that is impossible, I thought
maybe creating another of the same name (sort of) would be ok.
--
USENET would be a better place if everybody read: : mail address :
http://www.catb.org/~esr/faqs/smart-questions.html : is valid for :
http://www.netmeister.org/news/learn2quote2.html : "text/plain" :
http://www.expita.com/nomime.html : to 10K bytes :
Jul 17 '05 #10
In article <c3**********@ls219.htnet.hr>,
"Berislav Lopac" <be************@dimedia.hr> wrote:
That's all, except that instead of calling the functions defined in the two
class the usual way, you call them as $this->OneBigFatMasterFunction().


Ok, I guess this is what the other posted talked about too - I'll try it out -
thanks!

--
Sandman[.net]
Jul 17 '05 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
3327
by: hokiegal99 | last post by:
A few questions about the following code. How would I "wrap" this in a function, and do I need to? Also, how can I make the code smart enough to realize that when a file has 2 or more bad charcters in it, that the code needs to run until all bad characters are gone? For example, if a file has the name "<bad*mac\file" the program has to run...
99
5820
by: David MacQuigg | last post by:
I'm not getting any feedback on the most important benefit in my proposed "Ideas for Python 3" thread - the unification of methods and functions. Perhaps it was buried among too many other less important changes, so in this thread I would like to focus on that issue alone. I have edited the Proposed Syntax example below to take out the...
1
741
by: Bob Rock | last post by:
Hello, in the last few days I've made my first few attempts at creating mixed C++ managed-unmanaged assemblies and looking aftwerwards with ILDASM at what is visible in those assemblies from a managed point-of-view I've noticed that: 1) for each managed and unmanaged C function (not C++ classes) I get a public managed static method...
47
3804
by: Richard Hayden | last post by:
Hi, I have the following code: /******************************** file1.c #include <iostream> extern void dummy(); inline int testfunc() {
25
5380
by: Stijn Oude Brunink | last post by:
Hello, I have the following trade off to make: A base class with 2 virtual functions would be realy helpfull for the problem I'm working on. Still though the functions that my program will use a lot are the ones that are virtual and thus will slow down the calculation, at least that is what what I have read on several places on the...
2
3762
by: Bryan Olson | last post by:
The current Python standard library provides two cryptographic hash functions: MD5 and SHA-1 . The authors of MD5 originally stated: It is conjectured that it is computationally infeasible to produce two messages having the same message digest. That conjecture is false, as demonstrated by Wang, Feng, Lai and Yu in 2004 . Just recently,...
7
5879
by: Tim ffitch | last post by:
Hi I have created a VB dll file that contains common functions I use across various projects in VB, Access and Excel. Rather than have to code the functions in each I decided to use the dll route. The problem being that I can't call these functions from the query designer in Access. I decided that I would try the route of declaring the...
23
3964
by: Timothy Madden | last post by:
Hello all. I program C++ since a lot of time now and I still don't know this simple thing: what's the problem with local functions so they are not part of C++ ? There surely are many people who will find them very helpfull. gcc has them as a non-standard option, but only when compiling C language code, so I'm afraid there might be some...
7
3948
by: Immortal Nephi | last post by:
My project grows large when I put too many member functions into one class. The header file and source code file will have approximately 50,000 lines when one class contains thousand member functions. Is it normal how C++ Compiler can compile large class without any problem? Didn't C++ Compiler have rules to limit the number of member...
0
7384
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7322
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7567
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7718
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7316
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7665
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5239
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
4878
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
1
1790
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.