What is this -> in PhP? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

What is this -> in PhP?

-> was not there in the lessons xD

9th Jan 2017, 7:41 PM
SharletK
SharletK - avatar
3 Answers
+ 1
-> is not related to arrays, it's for object scope. class doSomething{ private $correctAnswer; function somethingDone($somethingHappened){ $this->correctAnswer = $somethingHappened; } } $ds = new doSomething(); $ds->somethingDone(true);
9th Jan 2017, 9:21 PM
Louis Milotte
Louis Milotte - avatar
+ 1
Ok thanks,
10th Jan 2017, 9:16 PM
SharletK
SharletK - avatar
0
Whenever you want to use an object’s method or property, you need to use the -> operator. e.g.: $company->name = 'Acme'; $company->getName();
9th Jan 2017, 10:55 PM
Jose Luis
Jose Luis - avatar