[thelist] PHP4 objects and a short introduction

Jon Molesa rjmolesa at consoltec.net
Sat Jul 1 13:13:06 CDT 2006


That makes sense and what I suspected.  I began thinking last night of 
storing the object in a session variable.  I know this is old hat for 
most.  And I know that OO was just introduced in PHP4, much improved in 
PHP5.  I read differing bits of info on PHP4 ability to store an object in 
the a session variable.  But from my own tests in appears unlikely.

if(isset($_SESSION['variable']))
{
 	$variable2 = $_SESSION['variable'];
}
else
{
 	$variable2 = new MyClass();
 	$_SESSION['variable'] = $variable2;
}

Subsequent calls to methods of $variable2 fail.

$variable2->MemberMethod();

Perhaps I could just assign the contents of the Class's array to a session 
var and only create the object if the session var is empty.  Thanks again.

On Fri, 30 Jun 2006, Anthony Baratta wrote:

> Jon Molesa wrote:
>>
>> Would that create the object $myObject each time or does PHP4 realize that
>> it has been created previously and just references it?  If it does create
>> the object each time is that the correct way to use objects?  Seems that
>> once it has been created my code should just be able to make use of it.
>> Similar in nature to session_start() recognizing that a session has
>> already been created.  Could someone please clear this up for me?  Thank
>> you and God bless.
>
> Only items stored in the Session Object (and the session object itself)
> are persistent between page calls. Every other object created within a
> page is create and destroyed within the context of the page.
>
> As soon as the code on a particular page is done, PHP cleans up and
> throws it all away.
>
>

Jon Molesa
rjmolesa at consoltec.net



More information about the thelist mailing list