Jump to content

Class Logic Issue


johndapunk

Recommended Posts

I am having a little problem understanding the logic behind this. I study some code (occasionally), and I saw this in IPB's scripts. At the begining of a class, it will have:
PHP Code:
[code]<?php
class classname {
var $ipsclass;
...
}
?>[/code]

and then later on, it is able to use the $ipsclass object like so:
PHP Code:
[code]$this->ipsclass->...[/code]
I just don't understand how it uses the $ipsclass object without declaring something like:
[code]$this->ipsclass = new ipsclass;[/code]

Here, I'll post my code so you might get a better point of it.

super.php:
PHP Code:
[code]<?php
/**
* Test Super Class
*
*/
global $SUPER;
$SUPER = new super;
REQUIRE_ONCE( 'test_three.php' );
class super {
public $num;
function __construct( ) {
    $this->num = 5;
    }
}
?>[/code]


test_three.php:
PHP Code:
[code]<?php
/**
* Test Three
*
*/

class three {
public function f( $x ) {
    $f = 5 * intval( $x );
    echo $f;
}
}
$three = new three;
$three->f( $super->num );
?>[/code]


And it echos "0", which obviously means that $super->num in test_three.php is undefined.

I have tried to figure out how it does it, but I still don't understand. If you get what I'm asking, please respond. If you think you might know the answer, but don't really understand the question, please IM me at jondapunk (AIM), or johndapunk@hotmail.com (MSN).
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.