Forum Moderators: coopster

Message Too Old, No Replies

PHP OOP question

         

L33t_J0rdan

7:30 am on Jun 15, 2010 (gmt 0)

10+ Year Member



Hi there guys,
Okay, I always wondered this, but if I declared like:
$it = include(config.php);

Could I then go onto say:
if($it -> $billy == "hello") {
echo $it -> $billy;
} else {
destroy_SESSION();
}

billy being declared in the file, config.
I've really wondered this for a while.

Matthew1980

10:21 am on Jun 15, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi there l33t_jordan

You would need to declare the instance of the class first before you can echo a var ;-)

Hope that helps you a bit, happy coding and welcome to the forum too.

Cheers,
MRb

Matthew1980

1:00 pm on Jun 15, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi there l33t_jordan

The above syntax would return an error anyway because your accessing the object incorrectly.

Wrong:
$var->$name;

Right:
$var->name;

Just thought i would mention this.

Cheers,
MRb

jatar_k

3:11 pm on Jun 15, 2010 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



it's an odd thing, I don't think it would work

you could include the contents of the file then preg_match it maybe but then it wouldn't be executed

if you include the file normally the vars that are initialized are within scope of the including script so just saying

if($billy == "hello") {
echo $billy;
} else {
destroy_SESSION();
}

would be adequate.

unless there is some other reason for the approach that I am not seeing.

L33t_J0rdan

3:27 pm on Jun 15, 2010 (gmt 0)

10+ Year Member



Thank you, guys. I have just wondered this, because I'm coding a 'habbo staff panel' for a client. Taking a look at other DJ panels show they use OOP but I can't find the root of the declaration. You guys can call me Jordan. And thanks again!

penders

12:21 pm on Jun 16, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



If your config.php script returns an instance of a class that contains billy as a public property, then this would work...

$it = include(config.php);  
if ($it->billy == "hello") {
echo $it->billy;
} else {
destroy_SESSION();
}


NB: Corrected '$' in class property, as per Matthew1980's post above