php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #51591 No warnings reported when invalidly adding automatically indexed array element
Submitted: 2010-04-18 21:04 UTC Modified: 2010-05-12 12:59 UTC
From: amcsi at mailbox dot hu Assigned:
Status: Not a bug Package: Unknown/Other Function
PHP Version: 5.3.2 OS: Ubuntu 10.04 beta 2
Private report: No CVE-ID: None
 [2010-04-18 21:04 UTC] amcsi at mailbox dot hu
Description:
------------
When an object with a __set() method has its non-existent array containing variable set by empty bracket syntax, it just creates a new object variable for the array, as if __set() weren't even there.

Test script:
---------------
<?php
class Foo {
    public $_vars = array();

    public function __set($var, $value) {
        $this->_vars[$var] = $value;
    }
}

$foo = new Foo;
$foo->bar[] = 'value';
var_dump($foo);
?>

Expected result:
----------------
__set() method called
object(Foo)#1 (1) {
  ["_vars"]=>
  array(1) {
    ["bar"]=>
    array(1) {
      [0]=>
      string(5) "value"
    }
  }
}

OR

<br />
<b>Fatal error</b>:  Cannot use [] for reading in <b>/home/amcsi/htdocs/lol.php</b> on line <b>11</b><br />



Actual result:
--------------
object(Foo)#1 (2) {
  ["_vars"]=>
  array(0) {
  }
  ["bar"]=>
  array(1) {
    [0]=>
    string(5) "value"
  }
}


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-05-12 12:59 UTC] mike@php.net
-Status: Open +Status: Bogus
 [2010-05-12 12:59 UTC] mike@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

This is not a set operation on the object, but rather setting an array entry on the property "bar".
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Wed May 07 16:01:30 2025 UTC