|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2007-03-20 20:28 UTC] helly@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Tue Oct 28 15:00:02 2025 UTC |
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