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).
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 9 years ago.
I'm a complete beginner in learning PDO for PHP and I actually haven't learned MySQL or MySQLi yet.
(Please take a look at the code below) I'm trying to make sense of what this " -> " arrow means and I couldn't find an answer anywhere else. Is the arrow semantically equivalent to the action word "perform" in every day english?
E.G for the codes below, $stmt (perform) -> closeCursor();
Code:
$stmt = $db->prepare($sql);
$stmt->execute(array($title,$entry));
$stmt->closeCursor();
Thank you.
The arrow is part of PHP's object syntax, it's saying:
$object->method();
In English is:
Run method on object
It's also used for accessing properties.
As PDO is a class in PHP and variables like $db are instances of that class, you're able to make use of the methods and properties in those instances.
Check out PHP's object docs for more info on the subject, and if you're new to Object Oriented programming then you'll need to research the subject.
That is php's object notation equivilent to . in Java and Javascript. Basically it's used to access a method or property of an object.
See the Objects and Classes documentation.
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.
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