What happened to the Messenger Plus! forums on msghelp.net?
Shoutbox » MsgHelp Archive » Skype & Technology » Tech Talk » PHP trouble

PHP trouble
Author: Message:
brian
Senior Member
****

Avatar

Posts: 819
Reputation: 43
– / Male / –
Joined: Sep 2004
O.P. PHP trouble
Never though I'd end up posting here, but i'm done.

I am coding a system right now, so in my main file I have between the lines of
code:
$sqlObj = new sql_system($sql_inf);

Then later on, I include another file, but I need the file to use my $sqlObj, but it is not able to access it for some reason.

Never worked alot over classing systems, but no idea what to do here, maybe declare $sqlObj as public, but it's already outside any if's and else's.

Thanks.
02-11-2006 09:33 PM
Profile PM Find Quote Report
J-Thread
Full Member
***

Avatar

Posts: 467
Reputation: 8
– / Male / –
Joined: Jul 2004
RE: PHP trouble
You are sure that it isn't declared within a function? Or do you try to use it in a function?

How about doing a really simple test. Make two files, test1.php and test2.php. In test2.php you do something with $sqlObj, very basic.

In test1.php you make the object like above and do:
code:
require("test2.php");

Still doesn't work? Then you should look to the server setting. Does it work now? Then it's your code. Maybe you did define or use it within a function. Use "global $sqlObj;" then.
02-11-2006 11:02 PM
Profile E-Mail PM Find Quote Report
rav0
Veteran Member
*****

Avatar
i have an avatar

Posts: 1419
Reputation: 29
35 / Male / Flag
Joined: Aug 2003
RE: PHP trouble
Somebody posted something similar to this before.

Apparantly, if in file1.php, you define a something, and then include file2.php, whatever you defined in file1.php doesn't work. file2.php gets processed by itself, and then pasted into file1.php. You will need to define something in file2.php for it to work, you can't define it in file1.php and include file2.php.
| [Image: dorsh] |

(\ /)
(O.o)
(> <)

This is Bunny. Copy Bunny into your signature to help him on his way to world domination
02-12-2006 08:10 AM
Profile E-Mail PM Web Find Quote Report
WDZ
Former Admin
*****

Avatar

Posts: 7106
Reputation: 107
– / Male / Flag
Joined: Mar 2002
RE: PHP trouble
quote:
Originally posted by rav0
Apparantly, if in file1.php, you define a something, and then include file2.php, whatever you defined in file1.php doesn't work. file2.php gets processed by itself, and then pasted into file1.php. You will need to define something in file2.php for it to work, you can't define it in file1.php and include file2.php.
That's nonsense. :p Or, at least, there's more to it than that.

Quick test... file1.php
code:
<?php
class wdz {
    var $lazy = 'very lazy';
}
$wdz = new wdz;
require './file2.php';
?>
file2.php
code:
<?php
echo $wdz->lazy;
?>
Executing file1.php will echo the string as expected.
02-12-2006 08:30 AM
Profile PM Web Find Quote Report
« Next Oldest Return to Top Next Newest »


Threaded Mode | Linear Mode
View a Printable Version
Send this Thread to a Friend
Subscribe | Add to Favorites
Rate This Thread:

Forum Jump:

Forum Rules:
You cannot post new threads
You cannot post replies
You cannot post attachments
You can edit your posts
HTML is Off
myCode is On
Smilies are On
[img] Code is On