473,503 Members | 1,910 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Auto prepend problem

Hi !

I'd like to ask everyone this question. I am currently maintain a
website which have hundreds of pages and lot of subdirectories. Most of
these pages contains a common function (let's call it "foo()" on top of
each of these pages. I've tried to use auto prepend and .htaccess to
prepend a file which contains an exact function foo() that is being
used on other pages.

I kept getting error "Cannot redeclare foo() in..." when I try to use
..htaccess and auto prepend feature. I've tried to remove foo() from
each page and use the foo() in the include file instead, but this
process take too much time. Is there anyway that I can tell PHP to
ignore the foo() function that is being redeclare in each page ? (I
know that I eventually have to remove foo() in every page).

Sorry for a lengthy question.

Thank you in advance,
Lazy Pig

Aug 28 '06 #1
5 3384
la*******@gmail.com wrote:
... Is there anyway that I can tell PHP to
ignore the foo() function that is being redeclare in each page ? (I
know that I eventually have to remove foo() in every page).
Sorry, don't know of such a solution. Could you do the following?
Write a script which browses all your pages and when it finds "foo()"
just rename it to something like "foo_old()".

Cheers

Aug 29 '06 #2

la*******@gmail.com wrote:
Hi !

I'd like to ask everyone this question. I am currently maintain a
website which have hundreds of pages and lot of subdirectories. Most of
these pages contains a common function (let's call it "foo()" on top of
each of these pages. I've tried to use auto prepend and .htaccess to
prepend a file which contains an exact function foo() that is being
used on other pages.

I kept getting error "Cannot redeclare foo() in..." when I try to use
.htaccess and auto prepend feature. I've tried to remove foo() from
each page and use the foo() in the include file instead, but this
process take too much time. Is there anyway that I can tell PHP to
ignore the foo() function that is being redeclare in each page ? (I
know that I eventually have to remove foo() in every page).

Sorry for a lengthy question.

Thank you in advance,
Lazy Pig
There are at least two ways you could do this: Put the declaration of
foo() inside this if block, if( !function_exists('foo')) { .... }, so
the function is only parsed if it hasnt already been declared. Another
way is put if( defined('fufile') ) {return;} define('fufile',1); at the
top of the file foo() is declared in - it quickly exists the include'd
file when it is included a 2nd/3rd/... time.

Tim

Aug 29 '06 #3
Hi !

Thank you for your response. I already tried the first method, but that
didn't work since auto prepend happened first, then the foo() function
in each page is being process next.

What do you mean "fufile" in your second method ? is it the include
file's name which contains foo() function ?

Thank you for your help,
Lazy Pig
Tim Hunt wrote:
la*******@gmail.com wrote:
Hi !

I'd like to ask everyone this question. I am currently maintain a
website which have hundreds of pages and lot of subdirectories. Most of
these pages contains a common function (let's call it "foo()" on top of
each of these pages. I've tried to use auto prepend and .htaccess to
prepend a file which contains an exact function foo() that is being
used on other pages.

I kept getting error "Cannot redeclare foo() in..." when I try to use
.htaccess and auto prepend feature. I've tried to remove foo() from
each page and use the foo() in the include file instead, but this
process take too much time. Is there anyway that I can tell PHP to
ignore the foo() function that is being redeclare in each page ? (I
know that I eventually have to remove foo() in every page).

Sorry for a lengthy question.

Thank you in advance,
Lazy Pig

There are at least two ways you could do this: Put the declaration of
foo() inside this if block, if( !function_exists('foo')) { .... }, so
the function is only parsed if it hasnt already been declared. Another
way is put if( defined('fufile') ) {return;} define('fufile',1); at the
top of the file foo() is declared in - it quickly exists the include'd
file when it is included a 2nd/3rd/... time.

Tim
Aug 29 '06 #4

la*******@gmail.com wrote:
Hi !

Thank you for your response. I already tried the first method, but that
didn't work since auto prepend happened first, then the foo() function
in each page is being process next.

What do you mean "fufile" in your second method ? is it the include
file's name which contains foo() function ?

Thank you for your help,
Lazy Pig
Hmm sorry it wont work - I misread the problem, thought you were
including a file on every page and the included file contained foo(),
having the function foo() defined every page is very different and what
I suggested won't work.

fufile was just the name of a constant to record whether a file had
been included or not, it could have been anything.

Tim

Aug 29 '06 #5

la*******@gmail.com wrote:
Hi !

Thank you for your response. I already tried the first method, but that
didn't work since auto prepend happened first, then the foo() function
in each page is being process next.
Try the first method but swap auto_prepend for auto_append..

Tim

Aug 29 '06 #6

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

Similar topics

6
26494
by: flamesrock | last post by:
so I know you can append a string. But how do you *prepend* a string, as shown in the following code #dirList = #string = """position""" #for x in len(dirList): # string += '>>...
9
11830
by: Prowler | last post by:
In our current application we have a page whose sole purpose for existence is to permit the user to select from a list (subsequent to our login page). We would like to have the list drop down...
1
2663
by: jas | last post by:
Hi, I just started to use DrPython and I have installed the CodeCompletion plugin. I am using DrPython 161 (on windows) with wxPython 2.6.1. Anyhow, when I try something like x = x. ...
5
5030
by: Samuel | last post by:
Hi, I am running into a problem of mixing UICulture = auto and allowing users to select culture using a dropdown list. I am detecting a querystring, "setlang", and when found, setting the...
37
5013
by: nobody | last post by:
I am writing a framework that other developers will write plug-ins for. I would like for one of the features of the framework to be to intercept all text written to stdout/stderr and prepend...
1
4181
by: y0sh1 | last post by:
I'm new at using macros in excel and need to prepend zeros to a column of data. i know i'll need an if statement with some kind of loop. the logic goes something like, select cell, if number is...
6
1533
by: Geoff Berrow | last post by:
I have a record in a MySql database which can be edited. Each time it is edited I want to give the user the opportunity to summarise the changes, which I store in a field. It doesn't really...
5
4816
by: lawpoop | last post by:
Hello - Is there an operator where I can prepend a string to a string, without repeating the variable name? I'm aware of the concatenation operator, where you can do $string .= $ending; ...
0
7287
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,...
1
7006
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...
0
7467
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...
0
5592
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4685
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...
0
3166
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1519
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 ...
1
744
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
397
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.