1 (edited by Limber 2006-04-20 16:50)

Topic: Cannot require_once parser

Hi everybody,

I have a problem. I've coded my own shoutbox and I want to parse smileys, bb, etc.

But when I try

require_once PUN_ROOT.'include/parser.php';

it gives me the "Fatal error: Cannot redeclare preparse_bbcode() (previously declared in /var/www/ab/include/parser.php:41) in /var/www/ab/include/parser.php on line 104"

Seems like require_once isn't doing what it's supposed to do!

So... what to do? Google found this thread
http://www.phpfreaks.com/forums/lofiver … 84050.html
but it did me no good.

Aftonbörsens skapare. Var med och starta något roligt och stort du med!

Re: Cannot require_once parser

Remove it, as it seems it's already loaded, perhaps by another plugin. Although require_once shouldn't give an error =/
Try require_once(PUN_ROOT.'include/parser.php'); or include_once(PUN_ROOT.'include/parser.php');

3 (edited by Limber 2006-04-20 17:37)

Re: Cannot require_once parser

Tried that, and removing it won't do me any good since I need to do

$cur_post['content'] = parse_message($cur_post['content'], 0);

Strange thing is that parse_message() isn't defined, but other functions in parser.php collide when including the file.

WTF? Hmm...

Edit: Ok so I moved some functions to a new file, uglyparser.php, like parse_message, do_smilies and whatever it was missing. Then, after adding do_clickable, I got this:

Fatal error: Cannot redeclare do_clickable() (previously declared in /var/www/ab/include/uglyparser.php:109) in /var/www/ab/include/parser.php on line 352

So basically I will be able to figure this out, but it will take a while, so if anyone knows exactly why this happens, please let me know big_smile

Aftonbörsens skapare. Var med och starta något roligt och stort du med!

Re: Cannot require_once parser

Just try with the removing.

Oh, and it's a fatal error, so script execution is halted wink

5 (edited by Limber 2006-04-20 19:26)

Re: Cannot require_once parser

Thanks elbekko, but as I explained I've tried removing, which leads me to not being able to call parse_message().

And I'm perfectly aware of what a fatal error means, I just don't get how I should include the parsing functions so that they are not declared twice.

Oh, and to clarify, I'm doing this from a miniportal (or whatever ConnorHD called it). That is of course the issue here...

www.aftonborsen.se

It's the shoutbox that needs parsin'... smile

Aftonbörsens skapare. Var med och starta något roligt och stort du med!

6 (edited by Limber 2006-04-21 09:13)

Re: Cannot require_once parser

So, thought I would share with you guys my solution to the problem...

I put require PUN_ROOT.'include/parser.php'; on top in header.php, thus allowing functions used in template replacements to access parsing. Then I removed the same require from viewtopic.php, delete.php and forum.php (the old index.php, remember that this is a punbb miniportal, not an original installation).

Ta-da! smile

Aftonbörsens skapare. Var med och starta något roligt och stort du med!

Re: Cannot require_once parser

My hosts recently upgraded to PHP 4.4.6 and apparently this version is fussy about re-declaring functions.

Do all PunBB pages call include/common.php ??

If so, I could just stick this in it..

require PUN_ROOT.'include/dblayer/common_db.php';

No?

--Alan

Re: Cannot require_once parser

AlanCollier wrote:

My hosts recently upgraded to PHP 4.4.6 and apparently this version is fussy about re-declaring functions.

Do all PunBB pages call include/common.php ??

If so, I could just stick this in it..

require PUN_ROOT.'include/dblayer/common_db.php';

No?

--Alan

What problem are you having?

Re: Cannot require_once parser

I'm using extern.php which includes:

require PUN_ROOT.'include/parser.php';

I call the script a couple of times on my front page and apparently PHP 4.4.6 is fussy (to the point of fatal error) when it tries to redefine existing functions. This only became a problem when my hosts upgraded!

Unless.. Is there a PHP configuration option to make it not fuss?

Is there a more elegant solution than making several copies of extern.php and commenting the call out in all but the first one to be called?

--Alan

Re: Cannot require_once parser

Use a URL include?

Re: Cannot require_once parser

Use a URL include?

Yeah I used to but I found that I was getting performance issues and my host suggested hard-coding the parameters in. As I understand it, using URL includes puts a lot more load on the server.

Now that I know what to comment out it's not so bad. It does seem to be a flaw with extern.php that you can only use it once in a page because of the repeated calls to parse/dblayer etc. Is there a way of detecting whether a function has already be defined and thus not call for those includes again?

Maybe a small global array in which you store details of which functions have already been defined?

--Alan

Re: Cannot require_once parser

use is_callable

and if its not, then do the require...

Re: Cannot require_once parser

AlanCollier: It's not a flaw because extern.php isn't meant to be used outside of URL includes. It's a page in and of itself wink

Re: Cannot require_once parser

Ok fair enough!

Is there an extern equivalent that will just output a single post?
Something that does all the parsing/security/etc. but outputs just 1 post? (given the post id of course)

--Alan