#24471 [Opn->Bgs]: protected data member redeclared as public

From: Date: Thu, 03 Jul 2003 10:05:21 +0000
Subject: #24471 [Opn->Bgs]: protected data member redeclared as public
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-43167@lists.php.net to get a copy of this message
 ID:               24471
 Updated by:       stas@php.net
 Reported By:      greg at chiaraquartet dot net
-Status:           Open
+Status:           Bogus
 Bug Type:         Zend Engine 2 problem
 Operating System: linux
 PHP Version:      5.0.0b1 (beta1)
 New Comment:

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). 


Previous Comments:
------------------------------------------------------------------------

[2003-07-03 00:09:43] 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


------------------------------------------------------------------------


-- 
Edit this bug report at http://bugs.php.net/?id=24471&edit=1



Thread (2 messages)

« previous php.bugs (#43167) next »