php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #46530 Object(with numeric named vars) -> array = isset(); bug;
Submitted: 2008-11-09 13:35 UTC Modified: 2008-11-09 14:36 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: serovov at gmail dot com Assigned:
Status: Not a bug Package: *General Issues
PHP Version: 5.2.6 OS: ANY
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 this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: serovov at gmail dot com
New email:
PHP Version: OS:

 

 [2008-11-09 13:35 UTC] serovov at gmail dot com
Description:
------------
When object has numeric named vars, and we cast this object to array. we have a problem with isset() checks;
PS. if is not a bug, please, explain why.

Reproduce code:
---------------
<?php
class buggy
{
    public function __construct(array $data)
    {
        foreach ($data as $key => $value) {
            $this->$key = $value;
        }
    }
}
function test_buggy($buggy)
{
    $kbuggy = array_keys($buggy);
    var_dump(
        $buggy,
        $kbuggy,
        isset($buggy[current($kbuggy)]),
        isset($buggy[$kbuggy[0]]),
        isset($buggy[$kbuggy[1]]),
        isset($buggy[$kbuggy[2]])
    );
}

$array = array(
    'a',
    'b',
    'c',
);

$buggy = new buggy($array);
$buggy = (array) $buggy;

echo "Test #1: ";
test_buggy($buggy);

echo "Test #2: ";
$buggy = unserialize(serialize($buggy));
test_buggy($buggy);
?>

Expected result:
----------------
Test #1:

array
  '0' => string 'a' (length=1)
  '1' => string 'b' (length=1)
  '2' => string 'c' (length=1)

array
  0 => string '0' (length=1)
  1 => string '1' (length=1)
  2 => string '2' (length=1)

boolean false

boolean false

boolean false

boolean false

Test #2:

array
  0 => string 'a' (length=1)
  1 => string 'b' (length=1)
  2 => string 'c' (length=1)

array
  0 => int 0
  1 => int 1
  2 => int 2

boolean true

boolean true

boolean true

boolean true


Actual result:
--------------
Test #1:

array
  0 => string 'a' (length=1)
  1 => string 'b' (length=1)
  2 => string 'c' (length=1)

array
  0 => int 0
  1 => int 1
  2 => int 2

boolean true

boolean true

boolean true

boolean true

Test #2:

array
  0 => string 'a' (length=1)
  1 => string 'b' (length=1)
  2 => string 'c' (length=1)

array
  0 => int 0
  1 => int 1
  2 => int 2

boolean true

boolean true

boolean true

boolean true


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-11-09 13:39 UTC] serovov at gmail dot com
Sorry, but i mix up Actual and Expected section:
------------------------------------------------
Actual:
Test #1:

array
  '0' => string 'a' (length=1)
  '1' => string 'b' (length=1)
  '2' => string 'c' (length=1)

array
  0 => string '0' (length=1)
  1 => string '1' (length=1)
  2 => string '2' (length=1)

boolean false

boolean false

boolean false

boolean false

Test #2:

array
  0 => string 'a' (length=1)
  1 => string 'b' (length=1)
  2 => string 'c' (length=1)

array
  0 => int 0
  1 => int 1
  2 => int 2

boolean true

boolean true

boolean true

boolean true

--------------------------------------------
Expected:

Test #1:

array
  0 => string 'a' (length=1)
  1 => string 'b' (length=1)
  2 => string 'c' (length=1)

array
  0 => int 0
  1 => int 1
  2 => int 2

boolean true

boolean true

boolean true

boolean true

Test #2:

array
  0 => string 'a' (length=1)
  1 => string 'b' (length=1)
  2 => string 'c' (length=1)

array
  0 => int 0
  1 => int 1
  2 => int 2

boolean true

boolean true

boolean true

boolean true
 [2008-11-09 14:36 UTC] felipe@php.net
This is a known issue and has been documented, see Bug #45959.
 [2008-11-09 14:36 UTC] felipe@php.net
This is a known issue and has been documented, see Bug #45959.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Mar 29 14:01:28 2024 UTC