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.
2 noob questions session_start() and ->
Moderator: General Moderators
- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
-> is the object instance access operator in php.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.
Code: Select all
$obj-&gt;someFunc();More detailed information.
- evilmonkey
- Forum Regular
- Posts: 823
- Joined: Sun Oct 06, 2002 1:24 pm
- Location: Toronto, Canada
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:
Now, let's say you want to make a crappy little honda civic:
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!
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;
}
}
?>Code: Select all
<?php
$civic = new Car();
$civic->engine = "V4";
$civic->bodytype = "car";
$civic->assigncolour("green");
echo $civic->colour; //should output "green"
?>Good luck!