Page 1 of 1
2 noob questions session_start() and ->
Posted: Fri Jul 29, 2005 2:08 am
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.
Posted: Fri Jul 29, 2005 3:20 am
by s.dot
session_start() will work on every page that's included.
Posted: Fri Jul 29, 2005 3:24 am
by mickd
k thanks

1 down 1 to go

Posted: Fri Jul 29, 2005 8:57 pm
by feyd
-> 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.
Posted: Fri Jul 29, 2005 9:58 pm
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!