Page 1 of 1

What does "->" mean?

Posted: Thu Oct 01, 2009 1:53 pm
by pentool
I was searching the php online docs and google but I guess because of the characters I cannot find the reference. What does this mean: "->" ?

eg:

Code: Select all

<?php print $language->dir ?>
Thanks!

Re: What does "->" mean?

Posted: Thu Oct 01, 2009 1:55 pm
by jackpf
It's accessing the property "dir" in "$language".

Read up on classes and object oriented PHP :)

Re: What does "->" mean?

Posted: Thu Oct 01, 2009 2:14 pm
by pickle
You'd use it in these situations:

Code: Select all

<?PHP
class Lang
{
  public $dir = 'ltr';
 
  public function setDir($dir)
  {
    $this->dir = $dir;
  }
  public function getDir()
  {
    return $this->dir;
  }
}
 
$language = new Lang();
$language->dir = 'rtl';  //The "language" object now has "rtl" as the value of it's property "dir"
echo $language->dir; //Echoes "rtl"
$language->setDir('ltr');
echo $language->getDir();//You can also use -> to access object methods

Re: What does "->" mean?

Posted: Thu Oct 01, 2009 2:30 pm
by pentool
Great, thanks!