i have the following problem and i was wondering if anyone can please HELP.
i created a class structure just for testing purposes to be later on implemented in a programm im working on. if it works of course!?
im then creating an object based on those classes enter information into it and i then want to keep it. and the problem i have is that because PHP4.2.5 treates object as if they where any other variable as soon as i jump to the template and back its GONE!!!.
so i tried to make a session of it and access it that way - FORGET ABOUT IT!!!
i tried to also send it through the header and thats when PHP STEPS ON ITS OWN FOOT!!!! becasuse you dont have to declare variables of specific types so PHP doesnt know what was just passed and all it said is e.g. user=Object you cant access the info within it.
(i had a similar problem trying to pass a two dimentional array that was created using a JavaScript through the header and on my PHP page it was seen as a comma separated string. needless to say i nearly broke the mavhine.)
OK!!! while i was typing this i came with an idea which worked!!! i included the second page (object_test1.php - see below) in the third page (object_test2.php - see below) and i got the value i wanted. BUT!!!
and this is a big "BUT" hahahahaha no pun intended, that means that ill have to include this in all the pages which use this object!? is there another way? and besides thats not the way that OO should work. i read that in PHP5 they sorted a lot of this problems unfortunately i dont have the privilage of using it because my company's SP does not have it installed on the server yet, BUGGER!!!!!
please does someone have a way.
this is my code:
1st page: object_test.php holds the class declaration
Code: Select all
<?php
class account
{
var $account_number;
function account($accno)
{
$this->account_number = $accno;
}
}
class status
{
var $status_type;
var $direction;
function status($stat_type, $direct)
{
$this->status_type = $stat_type;
$this->direction = new direction($direct);
}
}
class direction
{
var $direction;
function direction($direct)
{
$this->direction = $direct;
}
}
class individual
{
var $fname;
var $sname;
var $account;
var $status;
function individual($fname, $sname, $accno, $stat_type, $direct)
{
$this->fname = $fname;
$this->sname = $sname;
$this->account = new account($accno);
$this->status = new status($stat_type, $direct);
//print("user fname is = ". $this->fname . "\n");
//print("user sname is = ". $this->sname . "\n");
//print("account number is = ". $this->account->account_number . "\n");
//print("user status is = ". $this->status->status_type . "\n");
//print("direction is = ". $this->status->direction->direction . "<br>\n");
}
}
?>Code: Select all
<?php
require("object_test.php");
$user = new individual("tal", "orlik", "12", "seek", "wtoh");
$user2 = new individual("tim", "bielawsky", "13", "offer", "wtoh");
echo "<table><tr><td><a href ="object_test2.php">Object test</td></tr></table>";
?>Code: Select all
<?php
include("object_test1.php"); //NOT IN ORIGINAL CODE
print "<br>".$user->account->account_number;
?>Tal.
feyd | Please use
Code: Select all
tags when posting code. Read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]