what is the difference between $object::$variable and $object->variable [duplicate] - php

This question already has answers here:
What's the difference between :: (double colon) and -> (arrow) in PHP?
(6 answers)
Closed 8 years ago.
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?

$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.

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

Related

what is this "->" symbol called name? [duplicate]

This question already has answers here:
Reference Guide: What does this symbol mean in PHP? (PHP Syntax)
(24 answers)
Where do we use the object operator "->" in PHP?
(6 answers)
Closed 4 years ago.
What is this -> symbol Called in PHP. I know it can be interpreted as Equal Sign Right Angle Bracket. | can be called Pipe or OR. but my prof was asking the other term to call the -> symbol. It is for assigning a value to a key in array class. does anyone know what this is called?
This is called the Object Operator. It is used to access properties and methods inside a class, where you put the -> symbol after.
Example from the documentation:
<?php
class foo
{
function do_foo()
{
echo "Doing foo.";
}
}
$bar = new foo;
$bar->do_foo();
?>
As you can see, the do_foo() method is located in the foo class. To access the method outside the class, you need to use the -> symbol to access the properties or methods inside the given class.
Information from the PHP documentation:
Within class methods non-static properties may be accessed by using -> (Object Operator): $this->property (where property is the name of the property). Static properties are accessed by using the :: (Double Colon): self::$property. See Static Keyword for more information on the difference between static and non-static properties.

What is the difference between self and $this in php? [duplicate]

This question already has answers here:
When should I use 'self' over '$this'?
(23 answers)
Closed 7 years ago.
What is the difference between $this and self? When should we use each of them?
$this refers to the current instance. self refers to the current class.
In other words, you can use $this->someMember to refer to an instance member and self::$someStaticMember to refer to a static member.
$this points to current object where as self:: points to current class.

what does $this->variable mean [duplicate]

This question already has answers here:
Reference Guide: What does this symbol mean in PHP? (PHP Syntax)
(24 answers)
Closed 7 years ago.
$this->var
There's a "->" symbol when we call a variable, and i'd like to know what actually does the "->" means. I tried to do some research but the textbook and the internet don't explain this clealy.
Thanks in advance.
PHP has two Object Operator namely -> and ::
-> is used when you are trying to call a method on an Instance and / or access an Instance property.
:: is used when you want to call a static method or call a parent class's version of a method within a child class.

What does operator -> mean in PHP? [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicates:
What does the PHP syntax $var1->$var2 mean?
Reference - What does this symbol mean in PHP?
I'm looking at a PHP framework's code, and now and then the symbols "->" appear... for example:
$controller->permissionCheck($ret);
What does "->" stand for and what is used for?
In your example, $controller is a PHP object created somewhere, and permissionCheck is a function defined in that object that is being called with the variable $ret being passed to it. Check this: Reference - What does this symbol mean in PHP?.
It's used to address a function or property of a class.
In this case a function of the controller class seems to be called.
Operator -> is for access to the non-static members of $controller object. In your case, the member is the function permissionCheck.

What does :: mean in php? [duplicate]

This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
what is the “::” notation in php used for?
I noticed this code while modifying a friends code and noticed this piece of code: TestPages::LoadMenu();
what does :: mean in php?
A great answer would mean a lot.
Thanks!
It's the 'Scope Resolution 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.
http://php.net/manual/en/language.oop5.paamayim-nekudotayim.php
In layman terms it is used to call static Methods of a Class.
In your example, LoadMenu() is a static function of the TestPages class.
This means that you do not have to create an instance of a TestPages to call LoadMenu()
It is used to access static methods of class, static variables and constants
Read more
It means static class member access, in this case static method invocation.
It's used to access class methods / properties:
http://www.php.net/manual/en/language.oop5.paamayim-nekudotayim.php

Categories