What does "->" mean?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
pentool
Forum Newbie
Posts: 2
Joined: Thu Oct 01, 2009 1:51 pm

What does "->" mean?

Post 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!
User avatar
jackpf
DevNet Resident
Posts: 2119
Joined: Sun Feb 15, 2009 7:22 pm
Location: Ipswich, UK

Re: What does "->" mean?

Post by jackpf »

It's accessing the property "dir" in "$language".

Read up on classes and object oriented PHP :)
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Re: What does "->" mean?

Post 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
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
pentool
Forum Newbie
Posts: 2
Joined: Thu Oct 01, 2009 1:51 pm

Re: What does "->" mean?

Post by pentool »

Great, thanks!
Post Reply