Professional Web Applications Themes

#26364 [Opn->Bgs]: initializing class in other class vars value problem - PHP Development

ID: 26364 Updated by: [email]sniperphp.net[/email] Reported By: brightone at o2 dot pl -Status: Open +Status: Bogus Bug Type: Class/Object related Operating System: windows xp PHP Version: 4.3.4 New Comment: Change this: $this->root=$root; To: $this->root =& $root; and it'll work. Previous Comments: ------------------------------------------------------------------------ [2003-11-23 10:02:59] brightone at o2 dot pl Description: ------------ You have two classes, one initialized in another's contructor. After initializing the "child" class in "mother" constructor, all new values assigned to variables in mother are not visible in pointed classes. Reproduce code: --------------- <? class a{ var $temp; var $pointer; function a(){ $this->temp=10; $this->pointer=new b(&$this); $this->temp=20; echo " ...

  1. #1

    Default #26364 [Opn->Bgs]: initializing class in other class vars value problem

    ID: 26364
    Updated by: [email]sniperphp.net[/email]
    Reported By: brightone at o2 dot pl
    -Status: Open
    +Status: Bogus
    Bug Type: Class/Object related
    Operating System: windows xp
    PHP Version: 4.3.4
    New Comment:

    Change this:
    $this->root=$root;
    To:
    $this->root =& $root;

    and it'll work.



    Previous Comments:
    ------------------------------------------------------------------------

    [2003-11-23 10:02:59] brightone at o2 dot pl

    Description:
    ------------
    You have two classes, one initialized in another's contructor. After
    initializing the "child" class in "mother" constructor, all new values
    assigned to variables in mother are not visible in pointed classes.

    Reproduce code:
    ---------------
    <? class a{
    var $temp;
    var $pointer;
    function a(){
    $this->temp=10;
    $this->pointer=new b(&$this);
    $this->temp=20;
    echo " A: ".$this->temp;
    }
    }
    class b{
    var $root;
    function b($root){
    $this->root=$root;
    }
    function show_val(){
    echo " B: ".$this->root->temp;
    }
    }
    $r=new a;
    $r->pointer->show_val(); ?>

    Expected result:
    ----------------
    A: 20 B: 20

    Actual result:
    --------------
    A: 20 B: 10


    ------------------------------------------------------------------------


    --
    Edit this bug report at [url]http://bugs.php.net/?id=26364&edit=1[/url]
    sniper@php.net Guest

  2. #2

    Default #26364 [Opn->Bgs]: initializing class in other class vars value problem

    ID: 26364
    User updated by: brightone at o2 dot pl
    Reported By: brightone at o2 dot pl
    -Status: Open
    +Status: Bogus
    Bug Type: Class/Object related
    Operating System: windows xp
    PHP Version: 4.3.4
    New Comment:

    There is a little mistake in a the code above, here it goes:

    <? class a{
    var $temp;
    var $p_b;
    var $p_c;
    function a(){
    $this->p_b=new b(&$this);
    $this->p_c=new c(&$this);
    }

    function do_all(){
    $this->p_c->give_val();
    $this->p_b->show_val_c();
    echo " a: ".$this->p_c->something;
    }
    }

    class b{
    var $root;
    function b($root){
    $this->root=&$root;
    }
    function show_val_c(){
    echo " b: ".$this->root->p_c->something;
    }
    }

    class c{
    var $root;
    var $something;
    function b($root){
    $this->root=&$root;
    }
    function give_val(){
    $this->something="something";
    }
    }

    $r=new a;
    $r->do_all(); ?>


    Previous Comments:
    ------------------------------------------------------------------------

    [2003-11-24 05:02:18] brightone at o2 dot pl

    Okay, you're right here, my mistake. But there is a bug anyway, I'll
    show it on little bigger example:

    <? class a{
    var $temp;
    var $p_a;
    var $p_b;
    function a(){
    $this->p_b=new b(&$this);
    $this->p_c=new c(&$this);
    }

    function do_all(){
    $this->p_c->give_val();
    $this->p_b->show_val_c();
    echo " a: ".$this->p_c->something;
    }
    }

    class b{
    var $root;
    function b($root){
    $this->root=&$root;
    }
    function show_val_c(){
    echo " b: ".$this->root->p_c->something;
    }
    }

    class c{
    var $root;
    var $something;
    function b($root){
    $this->root=&$root;
    }
    function give_val(){
    $this->something="something";
    }
    }

    $r=new a;
    $r->do_all(); ?>

    Obviously, we want to see here "b: something b: something", but all we
    get is "b: a: something"

    ------------------------------------------------------------------------

    [2003-11-23 21:26:42] [email]sniperphp.net[/email]

    Change this:
    $this->root=$root;
    To:
    $this->root =& $root;

    and it'll work.


    ------------------------------------------------------------------------

    [2003-11-23 10:02:59] brightone at o2 dot pl

    Description:
    ------------
    You have two classes, one initialized in another's contructor. After
    initializing the "child" class in "mother" constructor, all new values
    assigned to variables in mother are not visible in pointed classes.

    Reproduce code:
    ---------------
    <? class a{
    var $temp;
    var $pointer;
    function a(){
    $this->temp=10;
    $this->pointer=new b(&$this);
    $this->temp=20;
    echo " A: ".$this->temp;
    }
    }
    class b{
    var $root;
    function b($root){
    $this->root=$root;
    }
    function show_val(){
    echo " B: ".$this->root->temp;
    }
    }
    $r=new a;
    $r->pointer->show_val(); ?>

    Expected result:
    ----------------
    A: 20 B: 20

    Actual result:
    --------------
    A: 20 B: 10


    ------------------------------------------------------------------------


    --
    Edit this bug report at [url]http://bugs.php.net/?id=26364&edit=1[/url]
    brightone at o2 dot pl Guest

Similar Threads

  1. class problem (class)
    By Savas Ates in forum ASP.NET Web Services
    Replies: 1
    Last Post: January 4th, 09:25 PM
  2. #26364 [Bgs->Opn]: initializing class in other class vars value problem
    By brightone at o2 dot pl in forum PHP Development
    Replies: 0
    Last Post: November 24th, 10:04 AM
  3. #26364 [NEW]: initializing class in other class vars value problem
    By brightone at o2 dot pl in forum PHP Development
    Replies: 0
    Last Post: November 23rd, 03:06 PM
  4. Problem with exception class and instance vars
    By Bennett, Patrick in forum Ruby
    Replies: 2
    Last Post: November 13th, 07:27 PM
  5. [PHP] vars between instantiate class...
    By Raditha Dissanayake in forum PHP Development
    Replies: 1
    Last Post: September 4th, 05:02 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139