Reply to Array assignment & references: strange behavior

Your name:

Reply:


Posted by Nenad Jovanovic on 06/30/05 11:09

Hi!

Under PHP 4.3.10, the following simple code behaves as expected: $b[1]
and $c are not modified by the final assignment to $a[1]:

Code 1:
********

$a[1] = 1;
$b[1] = 2;
$c = 3;

$a = $b;
$a[1] = 7;

// resulting mappings:
// $a[1] ... 7
// $b[2] ... 2
// $c ...... 3

However, the following two codes result in changes to $b[1] and $c, the
only difference to the previous code being the connection between $b[1]
and $c via a reference:

Code 2:
********

$a[1] = 1;
$b[1] = 2;
$c =& $b[1];

$a = $b;
$a[1] = 7;

// resulting mappings:
// $a[1] ... 7
// $b[2] ... 7
// $c ...... 7

Code 3:
********

$a[1] = 1;
$b[1] =& $c;
$c = 2;

$a = $b;
$a[1] = 7;

// resulting mappings:
// $a[1] ... 7
// $b[2] ... 7
// $c ...... 7

Is this effect intended? If it is, is it specified somewhere in the PHP
manual?

Thanks,

Nenad Jovanovic

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация