2 noob questions session_start() and ->

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
mickd
Forum Contributor
Posts: 397
Joined: Tue Jun 21, 2005 9:05 am
Location: Australia

2 noob questions session_start() and ->

Post by mickd »

hi, i was wondering if anyone could or knew where it says anything about what -> is and how its used. i remember reading someone saying that it is simular to 'of' but i cant figure out how its used.

also, just wondering if you have include 'page.php'; at the top of every page and in it contained
<?php
session_start();
?>

would session_start() still work on every page that has page.php included?

thanks.
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post by s.dot »

session_start() will work on every page that's included.
mickd
Forum Contributor
Posts: 397
Joined: Tue Jun 21, 2005 9:05 am
Location: Australia

Post by mickd »

k thanks :) 1 down 1 to go :wink:
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

-&gt; is the object instance access operator in php.

Code: Select all

$obj-&amp;gt;someFunc();
Where $obj is an object of some type, the "arrow" is being used to access the function (called a method) someFunc within the object.

More detailed information.
User avatar
evilmonkey
Forum Regular
Posts: 823
Joined: Sun Oct 06, 2002 1:24 pm
Location: Toronto, Canada

Post by evilmonkey »

More detailed explanation of OOP that always worked for me. Let's say you have the basic structure of a car. It has an engine (V4 or V6), a body type (car or van) and a pain scheme (blue or red). You'd code it like this:

Code: Select all

//this code is for PHP4, and is now slightly depreciated. The basiscs remain the same though.
<?php
class car {
   var $colour;
   var $engine;
   var $bodytype;
   
   function assigncolour($thecolour){
      $this->colour = $thecolour;
   }
}
?>
Now, let's say you want to make a crappy little honda civic:

Code: Select all

<?php
$civic = new Car();
$civic->engine = "V4";
$civic->bodytype = "car";
$civic->assigncolour("green");
echo $civic->colour; //should output "green"
?>
So that's a small introduction to methods (functions inside a class) and attributes (variables inside a class). If you want to know more about classes, you'd have to lean about constructors, destructors, parent and child classes, etc. Follow the link fyed gave you.

Good luck!
Post Reply