Jump to content

Quickie: Difference between '.' and '->' in accessing objects and classes


Recommended Posts

Hi guys, I couldn't find anything in the main PHP docs, but I was just wondering if I could get a quick clarifications between '.' (period or full stop) and '->' in accessing classes and objects. Mainly this is just for ease of coding for a database active records class.

 

Thanks guys, I look forward to joining this great community more :)

the . is used to stick things together. generally it's just the :: and -> for accessing class methods and properties.

 

$a = 'hello';
$b = 'world';
$c = $a . $b; // hello world

$class = new MyClass();
$class->doSomething();

echo $class->variable;

MyClass::doSomething(); // static method call

D'oh, I misinterpreted the error message. You are correct, you don't seem to be able to access objects through the period (as in C, which is where I went wrong). It's only for condensation.

 

Thanks for the quick reply.

D'oh, I misinterpreted the error message. You are correct, you don't seem to be able to access objects through the period (as in C, which is where I went wrong). It's only for condensation.

 

Thanks for the quick reply.

 

I think you meant concatenation. Condensation  is something entirely different ;)

. is the string concatenation operator, as Gamic pointed out. It combines two strings into one.

-> is the member-access operator, which accesses variables [methods] defined for an object.

:: is the static access operator, for accessing statics (variables/functions) defined for a class.

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.