FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


IN php what does the ON mean ->





Possum
Hi

I am integrating my phpBB forum into the rest of my site and would like to understand the php code I use.

Code:
<?php
define('IN_PHPBB', true);
$phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './';
$phpEx = substr(strrchr(__FILE__, '.'), 1);
include($phpbb_root_path . 'common.' . $phpEx);

// Start session management
$user->session_begin();
$auth->acl($user->data);
$user->setup();
?>


In the above code what does $user->session_begin(); do.

I know -> means on

I would like to know what on means.

Its very difficult to Google on but a link to its definition would be appreciated..

Thank you..
Fire Boar
I've never heard it described as the "on" operator, but $x->y means "the y on $x".

Here $user is an object. PHPBB is a lame example of objects, so let's roll our own.

Suppose I want to be able to represent a dog. The PHP code for a really basic dog is as follows:

Code:
class Dog
{
}


We can now create one or more dogs using

Code:
$dog1 = new Dog();
$dog2 = new Dog();
// and so on


The dog is pretty boring though, so let's give it properties and methods. Properties are variables defined within a class, and methods are functions defined within a class. The idea of a property/method is that calling them only affects the object it refers to. All properties and methods are either public (you can access them from anywhere), private (only the class defining them has access) or protected (can be accessed from the defining class or any class that extends it - don't worry about this now).

Code:
class Dog
{
  private $colour;
  private $happiness;

  public function __construct($colour)
  {
    $this->colour = $colour;
  }

  public function getColour()
  {
    return $this->colour;
  }

  public function setHappiness($happiness)
  {
    $this->happiness = $happiness;
  }

  public function getHappiness()
  {
    return $this->happiness;
  }

  public function talk()
  {
    return ($this->getHappiness() > 5 ? "Woof!" : "Whine...");
  }
}


So, now we have a dog with a colour. The __construct method is special, since it is run when you first create the object using "new". Let's make and work with a dog.

Code:
$dog1 = new Dog('white');
$dog2 = new Dog('brown');
$dog1->setHappiness(4);
$dog2->setHappiness(7);
print $dog1->talk(); // Whine...
print $dog2->talk(); // Woof!


Hopefully that gives you some idea. Look up PHP classes for more information.
Possum
Thank you so much for you fantastic answer..

Smile
snowboardalliance
Possum wrote:
Thank you so much for you fantastic answer..

Smile


If you want to know more, read up on OOP in PHP. This is a very basic part of it (calling methods on objects)
Fire Boar
And if you really want to get clued up on PHP/OOP, learn how to use a PHP framework! It starts off bewildering, then it starts to seem like magic, then you find you're writing code a heck of a lot quicker, or rather, the code you write does more. Symfony is a good one.
Aredon
As long as you have that code included on a page you'll have access to the $user->data array. Which you can use to verify things like username and login status and whatnot. I have quite a few phpBB functions I use for displaying recent posts and stuff if you'd like some of them.
Related topics
How To : Improve Your PHP Programming
site colse/open with php
Putting something on every page...
PHP include code problem
Does this really work
Try method in php does not work
having problems with sessions and login
footer.php date wrong
Question: PHP scripting + cron jobs
Layout Gap PRoblems with PHP/Javascript Combo
PHP help: Categories > Archives
Error I can't seem to fix.
[PHP] Parse error
PHP error page, die()
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.