-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?

3
  • A static property can be accessed without actual instance of the object Commented Sep 10, 2013 at 8:54
  • Instance properties vs. class properties. Two very different things. Read more about them. Commented Sep 10, 2013 at 8:54
  • Did you read the manual? Commented Sep 10, 2013 at 8:54

2 Answers 2

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.

Sign up to request clarification or add additional context in comments.

Comments

0

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.