Jump to content

[SOLVED] Question on php pointers


thenewperson

Recommended Posts

I think these this is a pointer "->"

my question is what does it do i often see it in open sources like

 

$this->connection = mysql_connect(DB_SERVER, DB_USER, DB_PASS) or die(mysql_error());

      mysql_select_db(DB_NAME, $this->connection) or die(mysql_error());

$this -> num_members = -1;

 

so on....

 

i see $this -> used so many times in same source so bit confued

my guess is their storing bunch of values into $this

but i dont understand the advantage of that

Link to comment
Share on other sites

-> is used to access methods and properties of an object in PHP OOP. There are plenty of examples there to help you understand.

 

The reserved variable $this is used to access methods and properties of a class from within one of it's methods.

Link to comment
Share on other sites

the $this->whatever syntax is PHP's way of accessing class variables/methods within a class. PHP doesn't have a pointer type.

 

in C++ it is similar to the this->whatever syntax, but in PHP you always must use $this->whatever when accessing attributes/methods inside a class, where in C++ you don't have to. It differs where in C++ this refers to the location in memory that the object resides (basically it is a pointer to itself) while in PHP it simply means it is referencing attributes or whatever in the class

Link to comment
Share on other sites

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.