Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2010-07-09 15:13:16

caruso_g
Member
From: Catania
Registered: 2009-04-11
Posts: 88
Website

Fatal error while including PHP code in an article

Hi guys,
I am trying to include a PHP application into a website putting the code into an article. The code I put in the article is:

notextile. <txp:php>
set_include_path(get_include_path().':'.getcwd().'/myPhpApp/');
include('myPhpApp/myScript.php');
</txp:php>

I followed guidelines here, but I got the following error:

Fatal error: Cannot redeclare class DB in /usr/share/pear/DB.php on line 433

Any idea of what is happening?

Thanks you all in advance for you help.

Giuseppe

Offline

#2 2010-07-09 15:22:55

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,942
Website GitHub

Re: Fatal error while including PHP code in an article

caruso_g wrote:

Fatal error: Cannot redeclare class DB in /usr/share/pear/DB.php on line 433

TXP uses class DB in txplib_db.php so you’re out of luck if Pear uses it as well I’m afraid.

I’ve always wondered why TXP uses this name without its own namespace or at least a prefix. I’d prefer if it was TXP_DB or something, but I don’t know how easily (if at all) it can be changed without breaking stuff.


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

#3 2010-07-09 15:40:07

caruso_g
Member
From: Catania
Registered: 2009-04-11
Posts: 88
Website

Re: Fatal error while including PHP code in an article

Thanks so much Stef,
I got the point and, yes, it would be great to fix that. Is there a place where to submit a ticket for future updates?
Anyway,
how can I fix that? Using a namespace declaration somewhere?

Offline

#4 2010-07-09 15:58:49

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,942
Website GitHub

Re: Fatal error while including PHP code in an article

caruso_g wrote:

Using a namespace declaration somewhere?

Assuming you have PHP 5.3.0+ you could try but I don’t know how successful it would be, simply because it needs to be the first thing in your file, before anything else is output. If you add it to the top of some TXP code then everything that comes later — plugins included (umm, I think) will probably be in that namespace. And if you try to just wrap Pear in a namespace it’ll probably fail because it’s not the first thing on the page.

Honest answer is I know next to nothing about namespaces in PHP.

If you’re desperate and fancied hacking TXP you could try this:

  1. in lib/txplib_db.php, alter class DB to class TXP_DB
  2. beneath that, alter function DB() to function TXP_DB()
  3. at the bottom of that function, change $DB = new DB; to $DB = new TXP_DB;
  4. For completeness, find $DB = new DB; and replace it with $DB = new TXP_DB; in import/import_b2.php, import/import_mtdb.php, and import/import_wp.php
  5. Upload and hope

I think that’s every reference and I don’t know of any plugins that directly access the DB class but I may be hopelessly wrong here (MLP maybe?)

If it works and nothing breaks then I guess we’ve inadvertently found the answer to how easy it is to change the DB name in TXP ;-)

Hope that helps.

EDIT: to submit a ticket for future updates, you could try posting in the Feature Ideas forum, or directly in the Development forum here for discussion. Or if you think it’s a worthy change that would benefit TXPkind you could always submit it as an Issue and we’ll look at it

Last edited by Bloke (2010-07-09 16:04:54)


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

#5 2010-07-09 16:06:25

Gocom
Developer Emeritus
From: Helsinki, Finland
Registered: 2006-07-14
Posts: 4,533
Website

Re: Fatal error while including PHP code in an article

Bloke wrote:

I’d prefer if it was TXP_DB or something, but I don’t know how easily (if at all) it can be changed without breaking stuff.

I’m not aware of any plugin that directly uses the class to anything. Some mods do modify txplib_db.php, but oh well, they are mods after all.

Changing the class should be relatively simple of replacing the global $DB (if you want to change that too) and the class in txplib_db.php (basically lines 19, 49, 73, 79, 117, and 170), and making changes to all the import scripts. Will break everything that tries to directly use the global or class tho.

Edit. Bloke is faster once again, heh :-)

Last edited by Gocom (2010-07-09 16:07:29)

Offline

#6 2010-07-09 16:11:21

caruso_g
Member
From: Catania
Registered: 2009-04-11
Posts: 88
Website

Re: Fatal error while including PHP code in an article

Thanks you guys, you are always so nice.
If you come in Italy, you’ll get a beer.

I’ll let you know what I’ll try.

Giuseppe

Offline

Board footer

Powered by FluxBB