php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #27193 the visibility of class constructor cannot be changed
Submitted: 2004-02-09 10:22 UTC Modified: 2004-02-09 11:19 UTC
From: andrey@php.net Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: 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: andrey@php.net
New email:
PHP Version: OS:

 

 [2004-02-09 10:22 UTC] andrey@php.net
Description:
------------
While it's no problem to change the visibility of a constructor (limit the visibility) when using the old way of declaring a constructor (function with the same name as the class), it's not possible to lower the visibility in a hierarchy where the constructors are named after the new standard : __construct() .
The engine have to check whether the name is __construct() (what about __destruct()? ), and not to complain in this case that the visibility is lowered.

The first example emits a fatal error. The second is perfectly valid.

Reproduce code:
---------------
php -r 'class a{public function __construct() {}} class b extends a {private function __construct(){}}'

php -r 'class a{public function a() {}} class b extends a {private function b(){}}'

Actual result:
--------------
PHP Fatal error:  Access level to b::__construct() must be public (as in class a) in Command line code on line 1

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-02-09 11:19 UTC] helly@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

expected behavior,

using old style constructors means using unrelated constructors.

using new style constructors means all rules apply. Hence you cannot decrease visility.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon Sep 16 23:01:28 2024 UTC