vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=15)
-   -   oop problem (https://vborg.vbsupport.ru/showthread.php?t=206209)

ragtek 02-22-2009 09:59 AM

oop problem
 
I'd like to call a Class inside a Class

PHP Code:

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/4...m-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.

Code:

outer_class()
{
    inner_class()
    {
          //...
          $inner_variable = 'inside';
    }
   
    $g = new inner_class();
    function access_inner_class_var()
    {
          return $g->inner_variable;
    }
}

$z = new outer_class();

[S]$failed = $z->$g->inner_variable;[/S]
$success = $z->access_inner_class_var();

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


All times are GMT. The time now is 09:24 PM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.03575 seconds
  • Memory Usage 1,723KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)bbcode_code_printable
  • (1)bbcode_php_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (4)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete