Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.php > #2754 > unrolled thread
| Started by | Thomas Mlynarczyk <thomas@mlynarczyk-webdesign.de> |
|---|---|
| First post | 2011-08-08 19:28 +0200 |
| Last post | 2011-08-18 19:26 -0400 |
| Articles | 6 — 3 participants |
Back to article view | Back to comp.lang.php
ArrayObject - copy or reference Thomas Mlynarczyk <thomas@mlynarczyk-webdesign.de> - 2011-08-08 19:28 +0200
Re: ArrayObject - copy or reference Jo Schulze <antispam@feuersee.de> - 2011-08-17 00:03 +0200
Re: ArrayObject - copy or reference Thomas Mlynarczyk <thomas@mlynarczyk-webdesign.de> - 2011-08-18 13:48 +0200
Re: ArrayObject - copy or reference Jerry Stuckle <jstucklex@attglobal.net> - 2011-08-18 13:54 -0400
Re: ArrayObject - copy or reference Thomas Mlynarczyk <thomas@mlynarczyk-webdesign.de> - 2011-08-18 20:44 +0200
Re: ArrayObject - copy or reference Jerry Stuckle <jstucklex@attglobal.net> - 2011-08-18 19:26 -0400
| From | Thomas Mlynarczyk <thomas@mlynarczyk-webdesign.de> |
|---|---|
| Date | 2011-08-08 19:28 +0200 |
| Subject | ArrayObject - copy or reference |
| Message-ID | <j1p6c2$nk2$1@news.albasani.net> |
Please consider the following example code: $array = array( 1, 2, 3 ); $obj = new ArrayObject( $array ); $obj[0] = 42; echo $array[0]; With PHP 5.2.0 this prints 42, with PHP 5.2.4 however, I get 1 (as expected). I have searched both on PHP's changelog [1] and Google, but could not find any information about this issue. I assume it is a bug that was fixed, but which one and in which version? Greetings, Thomas [1] <http://php.net/ChangeLog-5.php> -- Ce n'est pas parce qu'ils sont nombreux à avoir tort qu'ils ont raison! (Coluche)
[toc] | [next] | [standalone]
| From | Jo Schulze <antispam@feuersee.de> |
|---|---|
| Date | 2011-08-17 00:03 +0200 |
| Message-ID | <4e4ae91c$0$6579$9b4e6d93@newsspool3.arcor-online.net> |
| In reply to | #2754 |
Thomas Mlynarczyk wrote: > Please consider the following example code: > > $array = array( 1, 2, 3 ); > $obj = new ArrayObject( $array ); > $obj[0] = 42; > echo $array[0]; > > With PHP 5.2.0 this prints 42, with PHP 5.2.4 however, I get 1 (as > expected). I have searched both on PHP's changelog [1] and Google, but > could not find any information about this issue. I assume it is a bug > that was fixed, but which one and in which version? With PHP5.3.7rc this prints 42 which I would expect. The line $obj[0] = 42; overwites the value with hash key 0 I see no bug here.
[toc] | [prev] | [next] | [standalone]
| From | Thomas Mlynarczyk <thomas@mlynarczyk-webdesign.de> |
|---|---|
| Date | 2011-08-18 13:48 +0200 |
| Message-ID | <j2iu7p$9hs$1@news.albasani.net> |
| In reply to | #2858 |
Jo Schulze schrieb: >> $array = array( 1, 2, 3 ); >> $obj = new ArrayObject( $array ); >> $obj[0] = 42; >> echo $array[0]; >> >> With PHP 5.2.0 this prints 42, with PHP 5.2.4 however, I get 1 > With PHP5.3.7rc this prints 42 which I would expect. No it doesn't. I just installed PHP 5.3.7RC5 to test it. It prints 1. > The line > $obj[0] = 42; > overwites the value with hash key 0 It overwrites the value with hash key 0 in *$obj*. But it should not modify *$array*. > I see no bug here. There has definitely been a change in behaviour somewhere between 5.2.0 and 5.2.4. And that should be documented somewhere. Greetings, Thomas -- Ce n'est pas parce qu'ils sont nombreux à avoir tort qu'ils ont raison! (Coluche)
[toc] | [prev] | [next] | [standalone]
| From | Jerry Stuckle <jstucklex@attglobal.net> |
|---|---|
| Date | 2011-08-18 13:54 -0400 |
| Message-ID | <j2jjla$6hf$1@dont-email.me> |
| In reply to | #2870 |
On 8/18/2011 7:48 AM, Thomas Mlynarczyk wrote: > Jo Schulze schrieb: > >>> $array = array( 1, 2, 3 ); >>> $obj = new ArrayObject( $array ); >>> $obj[0] = 42; >>> echo $array[0]; >>> >>> With PHP 5.2.0 this prints 42, with PHP 5.2.4 however, I get 1 > >> With PHP5.3.7rc this prints 42 which I would expect. > > No it doesn't. I just installed PHP 5.3.7RC5 to test it. It prints 1. > >> The line >> $obj[0] = 42; >> overwites the value with hash key 0 > > It overwrites the value with hash key 0 in *$obj*. But it should not > modify *$array*. > >> I see no bug here. > > There has definitely been a change in behaviour somewhere between 5.2.0 > and 5.2.4. And that should be documented somewhere. > > Greetings, > Thomas > Thomas, I get 1 here also (php 5.2.4). I would consider this a bug - you might want to post it to bugs.php.net. -- ================== Remove the "x" from my email address Jerry Stuckle JDS Computer Training Corp. jstucklex@attglobal.net ==================
[toc] | [prev] | [next] | [standalone]
| From | Thomas Mlynarczyk <thomas@mlynarczyk-webdesign.de> |
|---|---|
| Date | 2011-08-18 20:44 +0200 |
| Message-ID | <j2jmip$h7$1@news.albasani.net> |
| In reply to | #2880 |
Jerry Stuckle schrieb: > I get 1 here also (php 5.2.4). I would consider this a bug - you might > want to post it to bugs.php.net. But the bug was in 5.2.0 and seems now fixed in 5.2.4. Please look at my code example again. I start with an array $array. Then I use that to create an ArrayObject $obj, which should be a *copy* of $array, not a reference to it. Now, whatever I do to $obj should not modify $array: $array = array( 1, 2, 3 ); $obj = new ArrayObject( $array ); $obj[0] = 42; echo $obj[0]; // This should print 42 and it does echo '<br>'; echo $array[0]; // This should print 1 and it does in 5.2.4 From your and Jo's postings I get the impression that you both think that $obj should be a reference to $array instead of an independent copy. But the docs do not mention any passing by reference (like "&$input"): ArrayObject::__construct() ([ mixed $input [, int $flags [, string $iterator_class ]]] ) There is, however, a user comment addressing this issue and giving a code example almost identical to mine: <quote>Note that the first argument to ArrayObject::__construct, the initial array, is passed by reference. ...</quote> Considering the date of that comment, it certainly refers to the old "pre-5.2.4" behaviour. Do you think this change in behaviour was unintentional (and thus not meant to be a bugfix) and nobody has noticed it so far and that's why I cannot find any official documentation about it? Anyway, I think the new behaviour is the "correct" one -- I would not expect $array to be passed by reference when it's not explicitly documented. Also, this behaviour makes more sense to me. Greetings, Thomas -- Ce n'est pas parce qu'ils sont nombreux à avoir tort qu'ils ont raison! (Coluche)
[toc] | [prev] | [next] | [standalone]
| From | Jerry Stuckle <jstucklex@attglobal.net> |
|---|---|
| Date | 2011-08-18 19:26 -0400 |
| Message-ID | <j2k72v$gjv$1@dont-email.me> |
| In reply to | #2882 |
On 8/18/2011 2:44 PM, Thomas Mlynarczyk wrote: > Jerry Stuckle schrieb: > >> I get 1 here also (php 5.2.4). I would consider this a bug - you might >> want to post it to bugs.php.net. > > But the bug was in 5.2.0 and seems now fixed in 5.2.4. Please look at my > code example again. I start with an array $array. Then I use that to > create an ArrayObject $obj, which should be a *copy* of $array, not a > reference to it. Now, whatever I do to $obj should not modify $array: > > $array = array( 1, 2, 3 ); > $obj = new ArrayObject( $array ); > $obj[0] = 42; > echo $obj[0]; // This should print 42 and it does > echo '<br>'; > echo $array[0]; // This should print 1 and it does in 5.2.4 > > From your and Jo's postings I get the impression that you both think > that $obj should be a reference to $array instead of an independent > copy. But the docs do not mention any passing by reference (like > "&$input"): > > ArrayObject::__construct() ([ mixed $input [, int $flags [, string > $iterator_class ]]] ) > > There is, however, a user comment addressing this issue and giving a > code example almost identical to mine: > > <quote>Note that the first argument to ArrayObject::__construct, the > initial array, is passed by reference. ...</quote> > > Considering the date of that comment, it certainly refers to the old > "pre-5.2.4" behaviour. > > Do you think this change in behaviour was unintentional (and thus not > meant to be a bugfix) and nobody has noticed it so far and that's why I > cannot find any official documentation about it? Anyway, I think the new > behaviour is the "correct" one -- I would not expect $array to be passed > by reference when it's not explicitly documented. Also, this behaviour > makes more sense to me. > > Greetings, > Thomas > > Yes, I think it's a bug in 5.2.0. But thinking more of it, I guess they won't accept a bug against 5.2.0 any more. -- ================== Remove the "x" from my email address Jerry Stuckle JDS Computer Training Corp. jstucklex@attglobal.net ==================
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.php
csiph-web