PDA

View Full Version : oop problem


ragtek
02-22-2009, 09:59 AM
I'd like to call a Class inside a Class

require_once(DIR . '/includes/twitter.php');

class vbtwitter{

/**
* Twitter object
*
* @var twitter object
*/
private $twitterconnection;

function __construct()
{

}

function init()
{
global $vbulletin;
$this->twitterconnection = new Twitter($vbulletin->userinfo['twitter_username'], $vbulletin->userinfo['twitter_password'], 'vbtwitter');
}

public function sendthread(&$threadid)
{
// and here now do things with $this->twitterconnection like $this->twitterconnection->method('foo');
}
Is something like this possible?

UKBusinessLive
02-22-2009, 11:22 AM
Is this any good for you http://stackoverflow.com/questions/482800/c-calling-methods-from-inside-class

ragtek
02-22-2009, 06:20 PM
thx but not realy
it's for c and not php

TigerC10
02-22-2009, 06:56 PM
You'll have to write wrapper functions. You can't directly access the nested classes from outside, so wrapper functions will let you do that.


outer_class()
{
inner_class()
{
//...
$inner_variable = 'inside';
}

$g = new inner_class();
function access_inner_class_var()
{
return $g->inner_variable;
}
}

$z = new outer_class();

$failed = $z->$g->inner_variable;
$success = $z->access_inner_class_var();


See? Alternatively, you could declare the inner class as public - but this is generally considered bad programming practice.