Current location: Hot Scripts Forums » Programming Languages » PHP » Class Logic Issue


Class Logic Issue

Reply
  #1 (permalink)  
Old 09-16-06, 06:32 PM
johndapunk johndapunk is offline
Newbie Coder
 
Join Date: Jan 2006
Posts: 43
Thanks: 0
Thanked 0 Times in 0 Posts
Class Logic Issue

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:

<?php

class classname {
var 
$ipsclass;
...
}
?>
and then later on, it is able to use the $ipsclass object like so:
PHP Code:

$this->ipsclass->... 

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).

Thanks
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #2 (permalink)  
Old 09-16-06, 07:09 PM
Nico's Avatar
Nico Nico is offline
Community Leader
 
Join Date: Sep 2005
Location: Spain
Posts: 8,074
Thanks: 11
Thanked 88 Times in 83 Posts
It's basically just creating a new object inside a class.

Something like this
PHP Code:

<?php



class wooo
{
    var 
$something;

    function 
wooo()
    {
        
$this->something = new yeah;
    }
}


class 
yeah
{
    function 
display()
    {
        echo 
'What';
    }
}

$test = new wooo;

$test->something->display();

?>
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #3 (permalink)  
Old 09-16-06, 07:28 PM
johndapunk johndapunk is offline
Newbie Coder
 
Join Date: Jan 2006
Posts: 43
Thanks: 0
Thanked 0 Times in 0 Posts
Yeah, I got that part of it. But what I don't get is how the $ipsclass variable has the class object in it without declaring any
PHP Code:

$this->ipsclass = new ipsclass 

Also, the classes with the
PHP Code:

<?php

class classname {
var 
$ipsclass;
...
}
?>
are in different files from the Super Class.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #4 (permalink)  
Old 09-16-06, 08:15 PM
johndapunk johndapunk is offline
Newbie Coder
 
Join Date: Jan 2006
Posts: 43
Thanks: 0
Thanked 0 Times in 0 Posts
Here, I'll post my code so you might get a better point of it.

super.php:
PHP Code:

<?php

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

<?php 

/**
* Test Three
*
*/

class three {
public function 
f$x ) {
    
$f intval$x );
    echo 
$f;
}
}
$three = new three;
$three->f$super->num );
?>
And it echos "0", which obviously means that $super->num in test_three.php is undefined.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #5 (permalink)  
Old 09-16-06, 08:32 PM
Barnz1986 Barnz1986 is offline
Aspiring Coder
 
Join Date: Jan 2006
Posts: 506
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by johndapunk
Yeah, I got that part of it. But what I don't get is how the $ipsclass variable has the class object in it without declaring any
PHP Code:

$this->ipsclass = new ipsclass 

Also, the classes with the
PHP Code:

<?php

class classname {
var 
$ipsclass;
...
}
?>
are in different files from the Super Class.
Strange, im sure the $this->ipsclass = new ipsclass must be somewhere in there.

Does the class extend another class? but then you would think the var $ipsclass would be in the super class etc.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #6 (permalink)  
Old 09-16-06, 08:34 PM
johndapunk johndapunk is offline
Newbie Coder
 
Join Date: Jan 2006
Posts: 43
Thanks: 0
Thanked 0 Times in 0 Posts
No, it doesn't. It's obvious that the file is getting the object from another file that it is INCLUDED into, and I'm assuming all files are linked to the ipsclass.php one way or another; but that still doesn't explain how the ipsclass class can be stored in the $ipsclass object without declaring it. Think it involves globals or something?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
nested class constructors stealth04 Windows .NET Programming 1 06-15-06 03:47 PM
Issue Tracking and Task management SlackeR Script Requests 8 10-05-05 05:29 PM
PHP global variables don't work inside a class wizkid PHP 4 12-20-04 04:31 PM
class designs:air traffic controller system lore00 Everything Java 0 08-09-04 11:25 AM


All times are GMT -5. The time now is 09:56 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.