can anyone explain how to use the->symbol as in:
PHP Code:<?php $this->lblLogout->Render(); ?>
can anyone explain how to use the->symbol as in:
PHP Code:<?php $this->lblLogout->Render(); ?>
Last edited by Snookerman; 05-04-2009 at 06:30 PM. Reason: added [php] tags
The -> characters are used for accessing objects.
Code:<?php class Write { function sayHi(){ echo "Hello"; } } $var = new Write();$var->sayHi();?>
Jeremy | jfein.net
more specifically they are to initiate a method.
Code:class YOURCLASS { public function FUNC() { /* something */ } public function FTN($tring, $arr) { /* something else*/ } }PHP Code:$var = new YOURCLASS();
$var->FUNC(); /* initiate the FUNC method of the YOURCLASS class */
$var->FTN('a1', ['z','y','w']);
okay, i also was about to ask this question but i saw it was already asked... would this be an appropriate use of it:
?PHP Code:function hi($name){
echo $name;
}
"hello"->hi();
The "->" in PHP is used to access properties and functions of an object. To use it, you'll need an object to use it on, like this:
Create a class (a blueprint for an object):
You can save this as a separate file, called helloObject.php. Then, in the script you want to use it in, first create an instance of your object with the "new" operator, and call the function you've defined in helloObject.php, passing it the name you want printed as a parameter:PHP Code:class helloObject {
public function hi($name) {
echo "Hello " . $name;
}
}
This will produce the output:PHP Code:$object = new helloObject();
$object->hi("Joe");
ggalan, the code you posted is saying that the variable $this has an object called lblLogout as one of its properties, and this object in turn has a function called Render() - this line calls that function.Code:Hello Joe
Thank you guys. This really clears the idea of oop in php.
Now, folks I just want to know how do you pronounce it. You know while working in a team some times you need to read your code. So, is there any standard pronunciation for the symbol " -> "?
![]()
I just say "arrow." But then, I don't talk about it much (aloud) with other programmers. Of course, I also say "S - Q - L" instead of "sequel."
"Submit a Link," what does that mean? He gave you an anwer, the link in his signature is his signature, it shows up every time he posts.
I usually say "This variable accesses this class, and returns blah blah blah..." I don't think that there is a standard way to say it.
Jeremy | jfein.net
Bookmarks