PHP4 Object Issues.

From: Date: Tue, 02 Aug 2005 20:49:22 +0000
Subject: PHP4 Object Issues.
References: 1  Groups: php.gtk.general 
Request: Send a blank email to php-gtk-general+get-6122@lists.php.net to get a copy of this message
Know it seems to be really a PHP bug, just to be sure this variable is not being altered by other function, i've created a static variable in the object as follows: class toolbox { var $window; var $ctree; var $menu; var $telas_menu = array(); var $tela_pai = null; var $selecionado = null; var $objeto_pai = null; var $node_selecionado = null; var $bla = "ugh"; }; And, at the selection function: function selecionar(&$node, $id) { // as Scott suggested global $projeto; $data = $this->ctree->node_get_row_data($node); $this->node_selecionado =& $node; $this->bla = "123"; echo "AHHHH " . $this->bla . "\n"; } And in another function where i call from inside the same object : function ativar_propriedades() { global $propriedades; echo "nas propriedades?\n"; print_r($this->bla); echo "fim\n"; $propriedades->localiza(&$this->selecionado,&$this->objeto_pai); } And, in the function where the error happens: function add_toolbox($objeto) { echo "add toolbox!\n"; print_r($this->node_selecionado); print_r($this->objeto_pai); echo "end toolbox!\n"; if(!$this) { echo "ERRRROO\n"; } else echo $this->bla . "\n"; } When I execute the selection function, the variable bla is assigned to 123, but here we have a strange behavior, when seeing the content of it from add_toolbox, it is "ugh", but when i print it from ativar_propriedades(), it is 123, even after i change the static value, both responses seem to be the same, I've checked if i'm not using another copy of the same object, but i'm not. How can PHP keep the original content of the variable bla even after it is altered? Piero -----Mensagem original----- De: Piero B. Contezini [mailto:piero@grupoamerican.com.br] Enviada em: terça-feira, 2 de agosto de 2005 17:26 Para: 'Scott Mattocks' Cc: php-gtk-general@lists.php.net Assunto: RES: [PHP-GTK] PHP4 Object Issues. The same problem ocurrs, the reference outside is ok, but inside add_toolbox is null. Piero -----Mensagem original----- De: Scott Mattocks [mailto:scott@crisscott.com] Enviada em: terça-feira, 2 de agosto de 2005 16:28 Para: php-gtk-general@lists.php.net Assunto: Re: [PHP-GTK] PHP4 Object Issues. Hello Piero, I think the problem you are having is related to references. Any time you assign a widget to some other variable, you need to use '&'. Change your code to this and see if it works: function selecionar(&$node, $id) { global $projeto; $data = $this->ctree->node_get_row_data($node); $this->node_selecionado =& $node; // this is the variable i need to store } Scott Mattocks -- PHP-GTK General Mailing List (http://gtk.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP-GTK General Mailing List (http://gtk.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php

« previous php.gtk.general (#6122) next »