#40872 [Asn->Csd]: inconsistency in offsetSet, offsetExists treatment of string enclosed integers

From: Date: Tue, 20 Mar 2007 20:28:40 +0000
Subject: #40872 [Asn->Csd]: inconsistency in offsetSet, offsetExists treatment of string enclosed integers
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-110614@lists.php.net to get a copy of this message
ID: 40872 Updated by: helly@php.net Reported By: piter75 at gmail dot com -Status: Assigned +Status: Closed Bug Type: SPL related -Operating System: Ubuntu Feisty, Windows XP +Operating System: * PHP Version: 5.2.1 Assigned To: helly New Comment: This bug has been fixed in CVS. Snapshots of the sources are packaged every three hours; this change will be in the next snapshot. You can grab the snapshot at http://snaps.php.net/. Thank you for the report, and for helping us make PHP better. Previous Comments: ------------------------------------------------------------------------ [2007-03-20 20:00:11] piter75 at gmail dot com Description: ------------ ArrayIterator's methods offsetSet and offsetGet treat the string enclosed integers ('1', '2', ....) as integers, but offsetExists treats them as strings and returns false even if the value exists at the specified offset. Reproduce code: --------------- <?php class Project { public $id; function __construct($id) { $this->id = $id; } } class ProjectsList extends ArrayIterator { public function add(Project $item) { $this->offsetSet($item->id, $item); } } $projects = new ProjectsList(); $projects->add(new Project('1')); $projects->add(new Project(2)); var_dump($projects->offsetExists(1)); var_dump($projects->offsetExists('2')); ?> Expected result: ---------------- boolean true boolean true Actual result: -------------- boolean true boolean false ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=40872&edit=1

« previous php.bugs (#110614) next »