I have some unclear (to me) behaviour in using classes and references to 
I submit you this code:

//some dummy classes
class A{
  var $score;

  function A(){
    $this->pippo = "pluto";
  function echoname(){
    echo (get_class($this)."\n");


class B {
  var $score;
  function B(){
    //assigning by value cause istances 
    //to be istances of a (same of $_SESSION[recorded])
    //but non reference is made, so it's a copy
    $this = $_SESSION["recorded"];

  function echoname(){
    echo (get_class($this)."\n");


class C {
  var $score;
  function C(){
    //assigning by reference cause istances 
    //to be istances of c and not the same of $_SESSION[recorded]
    $this = &$_SESSION["recorded"];

  function echoname(){
    echo (get_class($this)."\n");


//new object stored in session.
$_SESSION["recorded"] =& new A();

echo "<pre>";
echo "session[\"recorded\"] classname:  ";
$_SESSION["recorded"]->score = 99;

echo "test_var classname:  ";
$test_var = new B();
$test_var->score = 100;

echo "test_var2 classname:  ";
$test_var2 = new C();
$test_var2->score = 200;

echo "</pre>";

This three classes ar equal, except in the constructor. The problem is 
explained in the comments, but essentially is this:
How do I create an istance of a class that has is a reference to another 
istance previuously stored in session?
During this day of coding I finally (I hope) wrote a test that explains what 
I can't do.

I really appreciate any help.


PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to