Jump to content

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


jackson.rich

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.