This question already has answers here:
Reference Guide: What does this symbol mean in PHP? (PHP Syntax)
(24 answers)
What is this called in php: -> [duplicate]
(4 answers)
Closed 9 years ago.
I am trying to learn how a specific project works and while I can find most functions online, I found one that stumps me.
I see "->" appear every so often in the code, but have no idea what it does.
What does "->" mean in PHP or Joomla?
It's the object operator in PHP. It is used to access child properties and methods of classes. Its Javascript and Java equivalent is the . operator. It would be used in PHP like this
class foo{
public $bar="qux";
public function display(){
echo $this->bar;
}
}
$myFoo=new foo();
$myFoo->display(); //displays "qux"
Its like the . operator in C++ and Java. Refers to members within a class. C++ also uses the -> to access members when the variable preceding the -> is a pointer to a class rather than an instance of the class.
-> is the way used to call a method.
In C, C++, C#, Java you use . (dot) notation to call a method:
operation.sum(a, b);
In php you do it using ->
operation->sum(a,b)
Related
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.
This question already has answers here:
Reference Guide: What does this symbol mean in PHP? (PHP Syntax)
(24 answers)
Closed 6 years ago.
I am new at PHP and currently now i am working on moodle LMS tool.
I am referring view.php of scorm package and dont know why $cm->course this is used in php.
Please help.
Thanks in Advance
Have a look here
"->" means accessing the $cm object property course
$cm is an object, and course is a variable. Here you can see brief of PHP syntax with objects:
http://php.net/manual/en/language.types.object.php
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.
Reference: https://www.codeproject.com/questions/196270/what-is-meant-by-symbol-in-php
Note: I googled your exact question and got this result!
It is "object operator" - T_OBJECT_OPERATOR. It is used to access properties and methods of class on an object.
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.
This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
What's the difference between :: (double colon) and -> (arrow) in PHP?
Reference - What does this symbol mean in PHP?
I'm quite decent with PHP, but only procedural. So I decided to venture forth into learning object oriented. I'm getting the hang of it, and liking it quite well.
On PHP.net, I've always seen object oriented as mysqli::query.
However, every example I've seen uses mysqli->query as well as what I have always used.
Today, I ran across actually seeing :: used in a class example.
So now, my question is, is there a difference between :: and ->?
Is it like the difference between " and '?
:: is for calling static methods, -> is for instance methods
:: is the "scope resolution operator" (also aptly named Paamayim Nekudotayim), and is usually used to do a static (which means that you'll call the method in the context of the class itself, not the object) method call. There are however exceptions to this rule, such as attempting to call a parent method from an overriden method:
parent::foo(); // uses same context as when the method itself was called
It'll also allow you to reference static properties of the class, such as static properties and constants.
ClassName::FOO;
ClassName::$property = "bar";
-> is however used to reference a property or method in the actual object instance, and will always require an object instance to the left of the operator (such as $this).
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.