php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #40402 manipulate private and protected properties
Submitted: 2007-02-08 12:53 UTC Modified: 2007-02-08 12:56 UTC
From: jpieper at intergenia dot de Assigned:
Status: Not a bug Package: Class/Object related
PHP Version: 5.2.1RC4 OS: Irrelevant
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: jpieper at intergenia dot de
New email:
PHP Version: OS:

 

 [2007-02-08 12:53 UTC] jpieper at intergenia dot de
Description:
------------
After typecasting an object to an array you can iterate over the properties and manipulate private/protected properties.

Reproduce code:
---------------
<?php

class Foobar {
    private $oObject;
    public function __construct() {
        $this->oObject = new stdClass;
    }
}

$oFoobar = new Foobar;
$aProperties = (array)$oFoobar;
foreach ($aProperties as $mProperty) {
    if (is_object($mProperty) && ($mProperty instanceof stdClass)) {
        $mProperty->blaaa = 'fooo';
    }
}
var_dump($oFoobar);

?>

Expected result:
----------------
error because you must not access and rewrite/manipulate private/protected properties.

Actual result:
--------------
object(Foobar)#1 (1) {
  ["oObject:private"]=>
  object(stdClass)#2 (1) {
    ["blaaa"]=>
    string(4) "fooo"
  }
}

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-02-08 12:56 UTC] tony2001@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


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Oct 04 22:01:27 2024 UTC