Home › Forums › Back End › [Solved] Arrow Operator › Re: [Solved] Arrow Operator
The arrow is an accessor in object oriented php. Here’s a simple example:
public $h = “Hello”;
private $w = “World”;
function getStatement() {
echo $h . “, ” . $w;
}
}
And now, to show you how the arrow works:
So $myVar is an instance of the class above.
This is valid, because $h is a public variable in MyClass. Therefore, $myVar->h accesses the value of $h stored in this instance of MyClass.
This will cause a runtime error, because w is private. You cannot access private variables directly with the -> accessor.
Finally,
will echo "Hello, World", because the method is public (public is default if not explicitly declared). MyClass has access to its own variables, so World is printed out in this case, even though we couldn’t directly access it with:
This answer assumes you understand object oriented concepts at least a little bit. If you don’t, head on over to http://www.php.net/manual/en/language.oop5.basic.php.
Best of luck,
-D