Jump to content

Recommended Posts

In a class you have variable and functions. By calling $this->[function or var(without $)] inside a class, it will call the var or func that is defined in that class.

 

Use [any class name]->[func or var] in general. So replace $this by a class var (= $classvar = new yourclassname;) to call a func or var from another class. Can be in or outside a class.

 

FD

Oh ok,

 

So, just for my ease, I will compare it to a URL.

 

'$this->index' would be like http://localhost/index

and

'url->index' would be like http://53.156.23.4/index  (just a random IP)

 

Well thats how I understand it anyway, is that right? Sorry for the silly metaphor :P

 

Cheers,

Cobby

class test{

 

public $_x;

 

public function func1(){

echo $this->func2();

}

 

public function func2(){

return $this->_x = 3;

}

 

}

 

$f = new test();

$f->func1(); // echo 3

echo $f->func2(); //echo 3 as well

 

-> basically means use. so '$this' means this object. so $this->_x = 3; means set this ojbect's property _x to 3. and $this->func2(); means call method func2() inside of this object. its a pretty simple concept once you work with it for a while

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.