Possible Duplicate:
In PHP, whats the difference between :: and ->?
In PHP, what is the main difference of while calling a function() inside a class with arrow ->
and Scope Resolution Operator ::
?
For more clearance, the difference between:
$name = $foo->getName();
$name = $foo::getName();
What is the main profit of Scope Resolution Operator ::
?
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.
The arrow means the addChild is called as a member of the object (in this case $sxe). The double colon means that addChild is a member of the SimpleXMLElement class.
-> and => are both operators. The difference is that => is the assign operator that is used while creating an array.
== Operator: This operator is used to check the given values are equal or not. If yes, it returns true, otherwise it returns false. === Operator: This operator is used to check the given values and its data type are equal or not. If yes, then it returns true, otherwise it returns false.
$name = $foo->getName();
This will invoke a member or static function of the object $foo
, while
$name = $foo::getName();
will invoke a static function of the class of $foo
. The 'profit', if you wanna call it that, of using ::
is being able to access static members of a class without the need for an object instance of such class. That is,
$name = ClassOfFoo::getName();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With