php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #18543 Array returned from function with pointer at end
Submitted: 2002-07-24 13:28 UTC Modified: 2002-07-24 14:04 UTC
From: mikeboulet at newfangled dot com Assigned:
Status: Not a bug Package: Arrays related
PHP Version: 4.2.2 OS: Win2K/Linux RH 7.1
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: mikeboulet at newfangled dot com
New email:
PHP Version: OS:

 

 [2002-07-24 13:28 UTC] mikeboulet at newfangled dot com
It is expected that the $msgs array passed back out of the test() function call would have a pointer pointing to the first item. I confirmed that this works correctly under PHP 4.0.6. 

It doesn't work under 4.2.1 either.

Notice the output of the print_r()

// TEST SCRIPT

$newmsgs = test();
print_r( current( $newmsgs ));
function test()
{
	$msgs[][a] = 10;
	$msgs[][b] = 20;
	$msgs[][c] = 30;
	$msgs[][d] = 40;
	$msgs[][e] = 50;

	while( list( $idx, $msg ) = each( $msgs ) )
	{
		
	}

	return $msgs;
}


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-07-24 13:50 UTC] derick@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

Use reset() or foreach()
 [2002-07-24 14:04 UTC] mikeboulet at newfangled dot com
Just so you know, I did a lot of looking before I posted this bug. I still cannot find where in the php reference that it describes this behaviour. Do you know where this is documented?

This does work in PHP 4.0.6. I originally wrote the code under 4.0.6 and recently migrated the server to the 4.2.1/2 version.

Any ideas why the switch of behaviors? Was it a bug in php 4.0.6?

Thanks!
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Thu Jul 03 18:01:34 2025 UTC