Jump to content

Recommended Posts

I know that in JSP, there are such things known as bean to store data from one page to another. Another alternative to beam will be using SESSION object.

 

In php 5, OOP concept was introduced.

I read up alot of it.

I will like to know the following answer.

 

$a = new object();

 

The reference variable $a which has been created only exist on the current page, or current session.

 

Is there a way to pass data from a page to another page without using SESSION object

 

Ande

Thanks

Link to comment
https://forums.phpfreaks.com/topic/74992-php-classes-and-serialization/
Share on other sites

Save yourself a lot of time and just use sessions.

 

Like on most web applications, the choices of passing data from one area to another are:

 

saving in server memory

saving on server disk (flat file, sessions which default to using flat files, or database)

GET

POST

Cookies (saving on client disk)

 

Object serialization:

http://us3.php.net/manual/en/language.oop.serialization.php

 

In PHP5 your example, variable $a can be assigned to a session variable (i.e. $_SESSION['a'] = $a;) and PHP will automatically serialize and unserialize for you. The definition of the class (i.e. object() in this case) must be defined first before issuing a session_start().

 

hth.

 

 

EDIT:

 

MadTechie beat me to it. :)

From what i read from object serialization.

It is just converting an object or large array data into a string.

 

$a = new object();

$b=serialize($a);

 

In such case, $b will still be destroy once it leave the page unless

$_SESSION[abc] = $b;

is used?

 

 

Most application i programmed required me to pass argument from one page to another page only.

I realized i has been using alot of session variable.

 

Another fact is that I was using structured style to program my application.

I was wondering wat is the life span of the object created.

 

eg.

include class.php;

 

$a = new object();

 

assume class.php contain the object class that i need. Does it mean that everytime i used this class. I need to include it in every page.

 

 

In such case, $b will still be destroy once it leave the page unless

$_SESSION[abc] = $b;

is used?

Yes, that's correct. It must be saved in one of the ways I've already described. One of the reasons I showed you serialize, is because that's a way to pass something to the next page in a (GET/POST) like in a hidden form field. This is not recommended especially if you have sensitive information being saved and passed. I'm just explaining that it's possible because you asked for the ways it could be done.

 

Another fact is that I was using structured style to program my application.

I was wondering wat is the life span of the object created.

 

eg.

include class.php;

 

$a = new object();

 

assume class.php contain the object class that i need. Does it mean that everytime i used this class. I need to include it in every page.

Yes, class.php would have to be required every time on the pages where you wish to retrieve that data, and the class must be defined/included first before issuing a session_start().

 

 

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.