php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #38716 Fatal error: Cannot access private property
Submitted: 2006-09-04 20:08 UTC Modified: 2006-09-04 21:04 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: mmerlone at gmail dot com Assigned:
Status: Not a bug Package: Documentation problem
PHP Version: 5.1.6 OS: Ubuntu linux 6.06 2.6.15-26-686
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: mmerlone at gmail dot com
New email:
PHP Version: OS:

 

 [2006-09-04 20:08 UTC] mmerlone at gmail dot com
Description:
------------
Overloading method __set does not work for private variables as the example "Example 19-20. overloading with __get, __set, __isset and __unset example" from http://us3.php.net/manual/en/language.oop5.overloading.php .
This is the same of bug #34893 (http://bugs.php.net/bug.php?id=34893) which claims to be fixed, but is not.

Reproduce code:
---------------
<?
        class bla{
                private $variavel;
                function bla(){
                }
                function __set($vn, $vv){
                        $this->$vn = $vv;
                }
        }

        $bla = new bla();
        $bla->variavel = 1;
        echo "bla->variavel=".$bla->variavel."\n";
?>

Expected result:
----------------
bla->variavel=1

Actual result:
--------------
Fatal error: Cannot access private property bla::$variavel in /devel/testes/private.php on line 14

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-09-04 20:17 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


 [2006-09-04 20:54 UTC] mmerlone at gmail dot com
So, if it works as expected, the documentation should be fixed, since the example shows the __set changind a private variable.
 [2006-09-04 21:04 UTC] tony2001@php.net
Yes, __set() does change the private property, but your code tries to modify the property directly and this is totally different case.
The documentation is correct.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Tue Jul 08 03:01:32 2025 UTC