php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #32789 array_pop doesn't work correctly
Submitted: 2005-04-21 14:59 UTC Modified: 2005-04-28 12:02 UTC
Votes:1
Avg. Score:3.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: php at thoftware dot de Assigned:
Status: Not a bug Package: Arrays related
PHP Version: 4.3.11 OS: *
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: php at thoftware dot de
New email:
PHP Version: OS:

 

 [2005-04-21 14:59 UTC] php at thoftware dot de
Description:
------------
array_pop() removes data from objects via a method.

Reproduce code:
---------------
class foobar { 
  var $cache = array(); 
  function cache($j) { 
    if (!isset($this->cache[$j])) { 
      $this->cache[$j] = array( 
        'wert' => $j, 
        'text' => 'value: '.$j.'<br>', 
        'time' => 'set at '.date('h:i:s').'<br>', 
      ); 
    } 
    return($this->cache[$j]); 
  } 
} 
$foobar =& new foobar(); 
$v = $foobar->cache(3); 
echo $v['time']; 
$v = $foobar->cache(3); 
echo $v['time']; 
$v = $foobar->cache(3); 
echo $v['time']; 
$v = $foobar->cache(3); 
echo $v['time']; 
/* returns as expected
  set at 02:19:11
  set at 02:19:11
  set at 02:19:11
  set at 02:19:11
*/ 
$foobar =& new foobar(); 
echo array_pop($foobar->cache(3)); 
/* returns as desired
  set at 02:19:11
*/ 
$foobar =& new foobar(); 
echo array_pop($foobar->cache(3)); 
echo array_pop($foobar->cache(3)); 
echo array_pop($foobar->cache(3)); 
echo array_pop($foobar->cache(3)); 
/* returns as not desired
  set at 02:19:11
  value: 3
  3 

*/ 
$foobar =& new foobar(); 
$v = $foobar->cache(3); 
echo $v['time']; 
echo array_pop($foobar->cache(3)); 
/* returns as it should
  set at 02:19:11

  Fatal error: Only variables can be passed by reference in ... 
*/ 
Seems that the first call with a method isn't recognized as being not a variable =8-0.

Expected result:
----------------
see above

Actual result:
--------------
see above

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-04-22 15:54 UTC] php at thoftware dot de
Sorry, the fatal error results from the result of cache() being an empty array (but that may be another bug?), correct code should be:

Reproduce code:
---------------
class foobar {
  var $cache = array();
  function cache() {
    if (!count($this->cache)) {
      $this->cache[1] = array(
        'this is my cache<br>',
        'it\'s mine<br>',
        'noone else should be able to change it<br>',
        'it\'s forever mine<br>',
      );
    }
    return($this->cache[1]);
  }
}
$foobar =& new foobar();
echo array_pop($foobar->cache());
echo array_pop($foobar->cache());
echo array_pop($foobar->cache());
echo array_pop($foobar->cache());

Expected result:
----------------
it's forever mine 
it's forever mine 
it's forever mine 
it's forever mine

Actual result:
--------------
Fatal error: Only variables can be passed by reference in ...

Using a static variable within the method will work like the example using a plain function, using an object-variable will work like shown above, even if you remove the '[1]'-part.
 [2005-04-22 15:56 UTC] php at thoftware dot de
Sorry again, maybe I should stop coding %-(, this is the real 

Actual result:
--------------
it's forever mine
noone else should be able to change it
it's mine
this is my cache

for the example directly above ...
 [2005-04-23 09:05 UTC] alan_k@php.net
Sorry, but your problem does not imply a bug in PHP itself.  For a
list of more appropriate places to ask for help using PHP, please
visit http://www.php.net/support.php as this bug system is not the
appropriate forum for asking support questions.  Due to the volume
of reports we can not explain in detail here why your report is not
a bug.  The support channels will be able to provide an explanation
for you.

Thank you for your interest in PHP.

bugs is not a helpdesk - please leave this as bogus and ask on php-general.
 [2005-04-25 22:18 UTC] php at thoftware dot de
Maybe this one from Waq explains it in a better way why I think it's a bug: http://www.php.de/viewtopic.php?p=252840#252840 (it's from a german forum where the people tried to understand what I tried to say).

I didn't ask for help, the script that crashed because of this bogus bug was already fixed when I submitted this. Sorry for taking your time, surely PHP acts perfect in this case :-(

P.S. Why are you deleting your comments? Do you think it makes it even more bogus when it looks like I'm talking to myself? Not nice :-(
 [2005-04-26 14:08 UTC] php at thoftware dot de
Looks like nobody is listening here - sigh. After discussing this in another forum, we are still sure this _is_ a bug. As I was ordered not to set this bug back to open we are trying to start over with a new bug-report in a new location (it's not really a bug in array_pop() but something in the reference system). Someone with a hopefully better ability to explain where the bug is located will post it and I will add a link to it afterwards - hope that's o.k.
 [2005-04-28 12:02 UTC] php at thoftware dot de
I don't know, who is deleting my submissions, but I think it would be better to delete the whole thread instead of deleting only some submissions which makes the references in other submissions nonsense. I accept that you don't accept this as a bug and I wont post any new found bugs as it seems to be easyer to handle with bugs than to get a bug reported. Nice job.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Mar 29 11:01:29 2024 UTC