[PHP3] $obj1->array[$obj2]: can't set value From: pnet <email protected>
Date: 09/12/98

Can anybody tell me if this problem has a workaraound or if the
syntactically problem will be fixed, and if so, when that is likely to
happen?

It seems that the lack of pointers in PHP, combined with this syntactic
limitation make it impossible to set the values of properties of objects
that are nested inside arrays within objects.

Example:

<?
class obj1{
var $array;

 function init(){
  $this->array = array( new obj2 );
 }
 function display(){
  $item = $this->array[0];
  echo "$item->string\n";
 }
 function set_array( $value ){
  $temp = $this->array[0];
  // this is not a workaround since, again, $temp is not a pointer
  $temp = $value;
 }
}

class obj2{
 var $string = "initial_value";

 function set_string( $value ){
  $this->string = $value;
 }

}

$obj1 = new obj1;
$obj1->init();

// $obj1->array[0]->string isn't allowed by parser

$temp = $obj1->array[0];
// unfortunately, $temp is not a pointer to $obj2; it is a copy
$temp->string = "hello";
// even using an access function won't work:
$temp->set_string( "hello" );
$obj1->set_array( "hello" );
$obj1->display();
// prints "initial_value", not "hello"

?>

I cannot figure out any workaround to this problem.

It seems that I have come up against a rather serious limitation in PHP's
ability to support complex data-structures.

I thought the parser problem would have been fixed in the latest version
but it doesn't appear to have been fixed. Isn't anybody else concerned
about this or do you think I should switch to perl5 for this kind of thing?

Thanks.

- tppt: Tom Paine, Perpetual Traveller; webmaster <email protected>
================================================================
The USA has the highest incarceration rate in the world (1.6 m)
Most of those in prison are there for victimless 'crimes' (63%)
Since 1979, property seized without trial, has increased by 2500%
In the 'War On Drugs', drugs do not die. People do.

--
PHP 3 Mailing List   http://www.php.net/
To unsubscribe send an empty message to php3-unsubscribe <email protected>
To subscribe to the digest list:  php3-digest-subscribe <email protected>
For help: php3-help <email protected>  Archive:  http://www.php.net/mailsearch.php3