GetDotted Domains

Viewing Thread:
"OO PHP Question"

The "Freeola Customer Forum" forum, which includes Retro Game Reviews, has been archived and is now read-only. You cannot post here or create a new thread or review on this forum.

Sat 29/01/05 at 20:13
Regular
Posts: 10,364
Just trying to rearrange my PHP code into a more object orientated enviroment.

This isn't a problem, it's more of a question....

My class is located in a separate file called "clsGenFunctions", OK?

I have made one function that unsets some session variables, and this function sits within the class.

function unsetit() {
unset($_SESSION['title']);
unset($_SESSION['intro']);
unset($_SESSION['item']);
unset($_SESSION['product']);
unset($_SESSION['imgchecked']);
unset($_SESSION['insuranceopt']);
unset($_SESSION['feedback']);
unset($_SESSION['payment']);
unset($_SESSION['keyfeaturearray']);
}

OK, with me so far?

Seeing as this function is in a separate file to where it will be called, will it unset those session variables?

I am calling it using this

session_start();
include "clsGenFunctions.php";
$func = &New genfunctions; //Create object called func
$func->unsetit();

Seeing as session_start has been initiated at the beginning, the session variables should be unset successfully shouldn't they?

Cheers for any replies.
Sat 05/02/05 at 15:47
Regular
Posts: 88
You can store objects in sessions without serializing/unserializing them as this is done automatically. Just register the object variable in the session as normal, and you'll be able to use it in other pages. Remember to include the class definition before starting the session though, or PHP will give an unhelpful error message - just do:

include 'class_definitions.php'; //or whatever
session_start();

$myobect = $_SESSION['myobject']; //etc.
Fri 04/02/05 at 21:54
Regular
Posts: 10,364
Excellent, cheers Garin, that did the trick!
Fri 04/02/05 at 21:42
Regular
"Devil in disguise"
Posts: 3,151
gamesfreak wrote:
> Problem, how do I pass 'objects' between pages?
>

What you want to be looking at is http://uk2.php.net/serialize
Serialize your object, pass the string between pages as you like, by DB, sessions, cookies etc. and then unserialize in the new page.
Fri 04/02/05 at 21:15
Regular
Posts: 10,364
Just been doing some thinking and I feel I need to revamp the project into true object orientation. Meaning objects are used in the correct manner and classes are not just function storage.

Problem, how do I pass 'objects' between pages?

Example:

class object {
var $objectproperty1;
var $objectproperty2;

function objectmethod() {
//code goes here

}

}

As you know, the above class defines an object, correct?

$a = new object;
$a->objectproperty1="chickens";
$a->objectproperty2="pies";
?>

How would I send the object "$a" to another page?

Now sure if I'm making myself clear.

Cheers for any help.
Fri 04/02/05 at 21:14
Regular
Posts: 10,364
Edit: Double post :(
Sat 29/01/05 at 20:51
Regular
Posts: 10,364
Cheers Garin, now I have a problem with something else....
(With a different function)

function goto($loc) {
echo "";
}

Basically just takes the user to another page.

Can't seem to use it though, upon calling it with

$func->goto('design.php');

I just get the error: -

Fatal error: Call to a member function on a non-object in /var/www/localhost/htdocs/project/transaction.php on line 107

Any ideas?

EDIT: Managed to fix this!

I did it by making a new object. It seems that calling objects from within a function doesn't work without making a new one!

Anyway, managed to sort this again without even having to use a new object! Hurrah!
Sat 29/01/05 at 20:51
Posts: 15,443
gamesfreak wrote:

> Cheers for any replies.

Shucks, really there's no need.
Sat 29/01/05 at 20:43
Regular
"Devil in disguise"
Posts: 3,151
gamesfreak wrote:
> Seeing as session_start has been initiated at the beginning, the
> session variables should be unset successfully shouldn't they?

Yes it will be.
$_SESSION is a superglobal, as such its visible everywhere within the current execution of your program.
Sat 29/01/05 at 20:13
Regular
Posts: 10,364
Just trying to rearrange my PHP code into a more object orientated enviroment.

This isn't a problem, it's more of a question....

My class is located in a separate file called "clsGenFunctions", OK?

I have made one function that unsets some session variables, and this function sits within the class.

function unsetit() {
unset($_SESSION['title']);
unset($_SESSION['intro']);
unset($_SESSION['item']);
unset($_SESSION['product']);
unset($_SESSION['imgchecked']);
unset($_SESSION['insuranceopt']);
unset($_SESSION['feedback']);
unset($_SESSION['payment']);
unset($_SESSION['keyfeaturearray']);
}

OK, with me so far?

Seeing as this function is in a separate file to where it will be called, will it unset those session variables?

I am calling it using this

session_start();
include "clsGenFunctions.php";
$func = &New genfunctions; //Create object called func
$func->unsetit();

Seeing as session_start has been initiated at the beginning, the session variables should be unset successfully shouldn't they?

Cheers for any replies.

Freeola & GetDotted are rated 5 Stars

Check out some of our customer reviews below:

Great services and friendly support
I have been a subscriber to your service for more than 9 yrs. I have got at least 12 other people to sign up to Freeola. This is due to the great services offered and the responsive friendly support.
Many thanks!!
Registered my website with Freeola Sites on Tuesday. Now have full and comprehensive Google coverage for my site. Great stuff!!
John Shepherd

View More Reviews

Need some help? Give us a call on 01376 55 60 60

Go to Support Centre

It appears you are using an old browser, as such, some parts of the Freeola and Getdotted site will not work as intended. Using the latest version of your browser, or another browser such as Google Chrome, Mozilla Firefox, or Opera will provide a better, safer browsing experience for you.