-2

what is the difference between $object::$variable and $object->variable

both of them can be used to achieve the same but creates difference when the class member-variable is static as follows-

$object::$variable :- This syntax allows the static variable to be achieved through the object

But

$object->variable :- This syntax does not allow the static variable to be achieved through the object.

What is the semantic difference between the two?

Rajesh Paul
  • 6,793
  • 6
  • 40
  • 57

2 Answers2

2

$object::$variable and $object->variable

above both are are valid for accessing class property.

Only difference is that $object::$variable is used for access static property where as $object->variable is used for accessing property of class from instance.

For more words refer Amal Murali commented question link.

Dipesh Parmar
  • 27,090
  • 8
  • 61
  • 90
0

With $object::$variable you refer to the $variable of the class, $object->variable refers to the $variable of a instance of this class.