0
What differences are there between the keys "->" and "::" in PHP?
4 Answers
+ 1
The object operator, ->, is used in object scope to access methods and properties of an object. Itâs meaning is to say that what is on the right of the operator is a member of the object instantiated into the variable on the left side of the operator. Instantiated is the key term here.
Sample:
// Create a new instance of MyObject into $obj
$obj = new MyObject();
// Set a property in the $obj object called thisProperty
$obj->thisProperty = 'Fred';
// Call a method of the $obj object named getProperty
$obj->getProperty();
The operator,::, The Scope Resolution Operator (also called Paamayim Nekudotayim) or in simpler terms, the double colon, is a token that allows access to static, constant, and overridden properties or methods of a class.
When referencing these items from outside the class definition, use the name of the class. As of PHP 5.3.0, it's possible to reference the class using a variable. The variable's value can not be a keyword (e.g. self, parent, and static). Paamayim Nekudotayim would, at first, seem like a strange choice for naming a double-colon. However, while writing the Zend Engine 0.5 (which powers PHP 3), that's what the Zend team decided to call it. It actually does mean double-colon - in Hebrew!
Sample Example:
https://code.sololearn.com/wr3RpwI2Jrke/#php
+ 1
Thank you for detailed explanation đ
I should mention that I got surprised đź after learning that a operator of a PHP is called as a Hebrew word đ
The point I mainly wanted to learn is why different operators are allocated for such similar referencing operations. For example, the both could be as "->". Why did the designers of this holy language differentiate them?
+ 1
ArcturuS same here while I came to know abt thatđ€ enjoy đ
+ 1
Yepp, PHP is funny đ« I enjoy so much đđ