php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #43698 Assignment to inaccessible private property in __set() has no effect.
Submitted: 2007-12-28 16:20 UTC Modified: 2007-12-30 16:26 UTC
From: robin_fernandes at uk dot ibm dot com Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: 5.3CVS-2007-12-28 (snap) OS: Windows
Private report: No CVE-ID: None
 [2007-12-28 16:20 UTC] robin_fernandes at uk dot ibm dot com
Description:
------------
The assignment in the __set() method below is caught by the setter recursion guard. Subsequently, I would expect it to be treated like a direct assignment, and therefore to fail due to an attempt to write to another class's private property.
Instead, nothing happens at all.

I believe this is related to bug 38461, whereby a crash caused by a similar testcase was fixed, but the expected result of the assignment was not discussed.

Reproduce code:
---------------
<?php
class C {
  function __set($name, $value) {
    echo "In " . __METHOD__ . "('$name', '$value')\n";
    $this->$name = $value;
  }
}

class D extends C {
  private $hidden = "Original Value";
}

$d = new D;
$d->hidden = "New Value";
var_dump($d);
?>

Expected result:
----------------
In C::__set('hidden', 'New Value')

Fatal error: Cannot access private property D::$hidden in %s on line 5

Actual result:
--------------
In C::__set('hidden', 'New Value')
object(D)#1 (1) {
  ["hidden":"D":private]=>
  string(14) "Original Value"
}

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-12-30 16:26 UTC] iliaa@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-2026 The PHP Group
All rights reserved.
Last updated: Fri Jun 19 11:00:01 2026 UTC