php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #44769 declaring private magic methods should throw error
Submitted: 2008-04-17 23:15 UTC Modified: 2008-06-03 14:08 UTC
Votes:1
Avg. Score:3.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: todd at magnifisites dot com Assigned: felipe (profile)
Status: Closed Package: Scripting Engine problem
PHP Version: 5.2.5 OS: *
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: todd at magnifisites dot com
New email:
PHP Version: OS:

 

 [2008-04-17 23:15 UTC] todd at magnifisites dot com
Description:
------------
When using object overloading I thought I might receive at the very least a warning error if I attempted to declare any of the magic methods as private in a class definition as per the documentation:

"All overloading methods must be defined as public."

http://php.net/language.oop5.overloading.php

Also tested in PHP 6CVS-2008-04-17 (snap)

Reproduce code:
---------------
class MemberTest {
    /**  Location for overloaded data.  */
    private $data = array();
    private function __set($name, $value) {
        echo "Setting '$name' to '$value'\n";
        $this->data[$name] = $value;
    }
    private function __get($name) {
        echo "Getting '$name'\n";
        if (array_key_exists($name, $this->data)) {
            return $this->data[$name];
        }
    }
}
echo "<pre>\n";
$obj = new MemberTest;
$obj->a = 1;
echo $obj->a . "\n";
exit;

Expected result:
----------------
A FATAL error or at the very least a WARNING error with
    error_reporting  =  E_ALL | E_STRICT

Actual result:
--------------
<pre>
Setting 'a' to '1'
Getting 'a'
1


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-05-25 14:27 UTC] danielc at analysisandsolutions dot com
Marcus feels this is a bug and should be addressed (http://news.php.net/php.internals/37857).

Once this is fixed, the documentation bug should be updated (http://bugs.php.net/bug.php?id=43924).

Here are earlier bug reports covering this issue...

Documentation bugs that have been closed:
http://bugs.php.net/bug.php?id=31806
http://bugs.php.net/bug.php?id=40103

Illia marked this bogus saying it is the expected behavior.
http://bugs.php.net/bug.php?id=40056
 [2008-06-03 14:08 UTC] felipe@php.net
This bug has been fixed in CVS.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.
 
Thank you for the report, and for helping us make PHP better.

Fixed in 5_3 and HEAD.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Wed Apr 30 06:01:26 2025 UTC