php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #24471 protected data member redeclared as public
Submitted: 2003-07-03 00:09 UTC Modified: 2003-07-03 05:05 UTC
From: greg at chiaraquartet dot net Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: 5.0.0b1 (beta1) OS: linux
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: greg at chiaraquartet dot net
New email:
PHP Version: OS:

 

 [2003-07-03 00:09 UTC] greg at chiaraquartet dot net
Description:
------------
if a protected data member is re-declared as public in a child class, it is redefined as public.  Shouldn't the parent class protected declaration override the child class as it does for private?

Reproduce code:
---------------
<?php
class test
{
	protected $a = 6;
	function __construct()
	{
		print $this->a;
	}
}

class my extends test
{
	var $a = 7;
	function __construct()
	{
		print $this->a;
		parent::__construct();
	}
}
$a = new test; // 6
$a = new my; // 77
print $a->a; // should give error, is 7
$a->a = 4;
print $a->a; // 4
?>

Expected result:
----------------
Fatal Error, cannot redeclare a protected data member as public

Actual result:
--------------
67774

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2003-07-03 05:05 UTC] stas@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

You can increase visibility in derived classes (e.g., protected->public) but you can not decrease visibility (since it violates the base class API). 
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Sun Jul 27 02:00:03 2025 UTC