note 36593 deleted from language.oop by aidan
| From: | aidan@php.net | Date: | Sat, 03 Jul 2004 14:50:59 +0000 |
| Subject: | note 36593 deleted from language.oop by aidan | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-72441@lists.php.net to get a copy of this message | ||
Note Submitter: baZz
----
If you want to use a class within different pages there is more than one way to do it. The first one
is documented in a note above by russ, the only problem with this method is that you must have
register_globals = ON (in php.ini) and the php recomendation is to set it to off. The other way is
using session array:
<?php /*Page 1*/
session_start();
/*class declaration*/
class Employee{
var $name;
var $lastname;
function newEmpl($name,$lname,$noemp){
$this->name[$noemp] = $name;
$this->lastname[$noemp] = $lname;
}
function getEmpl($noemp){
return $this->name[$noemp];
}
}
$myempl = new Employee;
$myempl->newEmpl('Peter','Gabriel',0);
$myempl->newEmpl('Alex','Bowie',1);
$_SESSION['myempl'] = $myempl; /*Here we add our var to the session array*/
echo "<a href=\"testemp2.php\">go next page to test our class</a>";
?>
<?php/*Page 2*/
session_start();
echo "<p>Testing our class</p><br \>";
class Employee{
var $name;
var $lastname;
function newEmpl($name,$lname,$noemp){
$this->name[$noemp] = $name;
$this->lastname[$noemp] = $lname;
}
function getEmpl($noemp){
return $this->name[$noemp];
}
}
echo $_SESSION['myempl']->getEmpl(0);/*This should print the name of the first employee
that we add in the other page*/
?>
After this you can use the object within the whole session.
Good Luck.