0

What differences are there between the keys "->" and "::" in PHP?

16th Aug 2020, 5:09 AM
ArcturuS
ArcturuS - avatar
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
16th Aug 2020, 5:47 AM
Bits!
+ 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?
16th Aug 2020, 7:06 AM
ArcturuS
ArcturuS - avatar
+ 1
ArcturuS same here while I came to know abt thatđŸ€˜ enjoy 😁
16th Aug 2020, 7:26 AM
Bits!
+ 1
Yepp, PHP is funny đŸ’« I enjoy so much 👍🙂
16th Aug 2020, 7:28 AM
ArcturuS
ArcturuS - avatar