php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #6231 Reference parsing problem
Submitted: 2000-08-18 04:11 UTC Modified: 2002-06-01 11:40 UTC
From: rezinkin at mail dot ru Assigned:
Status: Closed Package: Scripting Engine problem
PHP Version: 4.1.0 OS: Linux
Private report: No CVE-ID: None
 [2000-08-18 04:11 UTC] rezinkin at mail dot ru
+++  Wrong class copieng  +++

<?
/*
Class BOMain1 and BOMain2 are different in one string see below
*/

 
  class BOMainstr{
   // Class attributes
   var $ID;                  // Object ID (integer) 
  } // end class definition

//-----------------------Class 1----------------------------
  class BOMain1{
   var $storage; //nested object

   function BOMain1 () 
   {
    $this->storage = new BOMainstr();
   }

   function get()   {
       return $this->storage->ID;
   }

   function set($ID)   {
      $this->storage->ID = $ID;
   }
  } // end class definition

//-----------------------Class 2----------------------------  class BOMain2{
   var $storage; //nested object

   function BOMain2 () 
   {
    $this->storage = new BOMainstr();
    settype($this->storage,'object');     // Different string
   }

   function get()   {
       return $this->storage->ID;
   }

   function set($ID)   {
      $this->storage->ID = $ID;
   }
  } // end class definition




  $A = new BOMain1();
  $A->set(1);
  $B = $A;
  $B->set(2); 
  echo "A->get() =>" . $A->get() .'<BR>';
  echo "B->get() =>" . $B->get() .'<HR>';

  $C = new BOMain2();
  $C->set(1);
  $D = $C;
  $D->set(2); 
  echo "C->get() =>" . $C->get() .'<BR>';
  echo "D->get() =>" . $D->get();

?>

Patches

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2000-08-18 04:14 UTC] rezinkin at mail dot ru
How working object copieng?
Object copy as reference or as object copy?
 [2000-08-18 06:21 UTC] waldschrott@php.net
There?s really some problem here, I?ve cut down the code to
illustrate the problem. After calling settype() on an
already existent object (really don?t needed) named
$this->prop, settype() changes that property to a reference
(see var_dump() output)... apparently to a reference to the
equivalent property of another object, I can?t imagine that
was intended...
perhaps zend tried to be smart in any way...

class BOMainstr{  }

class BOMain2{

function BOMain2 () {
 $this->storage = new BOMainstr();
 var_dump($this->storage);var_dump($this);
 settype($this->storage,'object');
 var_dump($this->storage);var_dump($this); }

function get() { return $this->storage->ID; }
function set($ID) { $this->storage->ID = $ID; } }


$C = new BOMain2();
$C->set(1);
$D = $C;
$D->set(2);
echo "C->get() =>" . $C->get() .'<BR>'; echo "D->get() =>" .
$D->get(); ?>
 [2000-08-31 08:56 UTC] stas@php.net
Well, I guess you shouldn't use settype there. I don't see why you should.
 [2001-12-12 08:02 UTC] yohgaki@php.net
Just an update.
I verified with Linux and 4.1.0. I agrree with the last comment. There is no need to use settype()....
But this problem should be addressed...
 [2002-06-01 11:40 UTC] mfischer@php.net
This is fixed with the new ZE2 (the property is no longer suddenly turning into a reference).
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Aug 03 06:01:32 2024 UTC