vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=15)
-   -   What is $this->? (https://vborg.vbsupport.ru/showthread.php?t=93720)

Guest190829 08-06-2005 04:46 AM

What is $this->?
 
OOP is giving me a headache. I'm working on vbspace, and I'm just messing around with the space class...is this correct for the most part? It's not the full class just one function

PHP Code:


<?php

class space //myspace class: the backbone of the hack.
{
   var 
$type;
   var 
$cache;

   public function 
get_soptions()
   {
       
$options $db->query_read("SELECT * from " TABLE_PREFIX " space_options");
       
       while (
$soptions $db->fetch_array($options))
       {
          
$this->type $soptions[type];
          
$this->cache $soptions[cache];
       }
    }
}

?>

If not, can you explain what $this-> is? I'm seeing it everywhere, and I think I have it right. It's just a pseudo instance of a the current class. Am I right?

Adrian Schneider 08-06-2005 04:51 AM

Sadly, yes.

necrotic 08-06-2005 05:00 AM

Also, make sure $db is globalized somehow (add global $db before calling it for example).

Guest190829 08-06-2005 05:46 AM

Just another question, when I use the class and make a new instance of it

PHP Code:

 $new = new space(); 

Would $new->cache be equal to $this -> cache? I'm guessing it should...

Marco van Herwaarden 08-06-2005 06:33 AM

Yes, as long as you are inside a function of that class.

Guest190829 08-06-2005 06:47 AM

How would I get $new->cache to have the same value outside of the function? Make it global?

Marco van Herwaarden 08-06-2005 06:53 AM

Outside your class you would use $new->cache, inside you use $this->cache

Guest190829 08-06-2005 06:55 AM

Okay, thanks Marco! :)


All times are GMT. The time now is 08:06 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.00944 seconds
  • Memory Usage 1,721KB
  • 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
  • (2)bbcode_php_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (8)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