php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #45334 Method hiding/visibility issue
Submitted: 2008-06-23 09:02 UTC Modified: 2008-06-23 12:27 UTC
Votes:1
Avg. Score:1.0 ± 0.0
Reproduced:0 of 1 (0.0%)
From: kristianoye at gmail dot com Assigned:
Status: Not a bug Package: Class/Object related
PHP Version: 5.2.6 OS: Windows XP
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: kristianoye at gmail dot com
New email:
PHP Version: OS:

 

 [2008-06-23 09:02 UTC] kristianoye at gmail dot com
Description:
------------
This issue was brought up in Bug #42830 but the bug was closed as 'Bogus' but to me it seems to be a valid issue:

I am working on a small framework of my own and all objects share a common ancestor (base object) that defines __construct as public.  I cannot redefine the visibility of __construct in the base without breaking other classes, yet I still want this derived, singleton to share the relation.

Addendum: This seems to be the case with any method, actually, not specific to __construct().  I tried defining a 'GetMessage()' method in the same class structure.  

Reproduce code:
---------------
class BaseObject
{
   public function GetMessage()  {  return "foo1";  }
}

class RequestObject extends BaseObject
{
   public function GetMessage()  {  return "foo2";  }
}

class CurrentRequest extends RequestObject
{
   private function GetMessage()  {  return "top secret";  }
}

Expected result:
----------------
No errors for restricting visibility of methods in derived classes (I can understand not letting you *increase* visibility of derived methods, but not the other way around).

Actual result:
--------------
PHP Fatal error:  Access level to CurrentRequest::GetMessage() must be public (as in class RequestObject) in C:\kristian\workspace\guild\foo.php on line 15

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-06-23 12:27 UTC] johannes@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

These rules are a central part of the object model, it was designed to work that way and we don\'t want to change it.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu May 23 03:01:28 2024 UTC