Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
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
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
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
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:
- in
lib/txplib_db.php
, alterclass DB
toclass TXP_DB
- beneath that, alter
function DB()
tofunction TXP_DB()
- at the bottom of that function, change
$DB = new DB;
to$DB = new TXP_DB;
- For completeness, find
$DB = new DB;
and replace it with$DB = new TXP_DB;
inimport/import_b2.php
,import/import_mtdb.php
, andimport/import_wp.php
- 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
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
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