Bug #52245 [Opn]: Private member of parent class accessible from child class.

2010-07-28 Thread johannes
Edit report at http://bugs.php.net/bug.php?id=52245&edit=1

 ID: 52245
 Updated by: johan...@php.net
 Reported by:phpamid at gmail dot com
 Summary:Private member of parent class accessible from child
 class.
 Status: Open
 Type:   Bug
 Package:*General Issues
 Operating System:   Windows 7 x64
 PHP Version:5.3.2
 Block user comment: N

 New Comment:

Private enforces encapsulation, a key element of OOP. The current
behavior ensures you can extend the class without an effect on 
show_private_member() and whatever happens in there. With your change
extending the class can hae an effect (by accident) on the method.


Previous Comments:

[2010-07-27 09:43:48] phpamid at gmail dot com

Could you please answer to my questions?


[2010-07-14 09:25:32] phpamid at gmail dot com

1) Answer for your question "Are you looking for protected elements?" is
"Bug #52245 Private member of parent class accessible from child
class."



2) Why you say that show_private_member() belongs to Parent class, if it
is inherited by its Child? In addition, I redefined the private member
in Child class - then, according to the paradigm of OOP polimoryizm, the
method should return a value of Child private member, otherwise all you
have said is contrary to OOP, in particular, to polymorphism.


[2010-07-08 13:00:41] johan...@php.net

You are calling show_private_member(). That method belongs to Father and
therefore has access to Father's private elements. The method has no
access to other class's private elements. Are you looking for protected
elements?


[2010-07-04 15:11:05] phpamid at gmail dot com

as for your code:



class A

{

private $a = "a";

}

class B extends A

{

private $a = "b"; // is this an error?

}



i think every class has own private member, so there is no error.



Ok, I got you.

I hope that this issue will be clarified.

Thank you for discussion.


[2010-07-04 14:32:12] giorgio dot liscio at email dot it

in fact if you use protected instead of private it works as expected

but the "private" issue should be clarified, i think



* i'm sorry for the second post




The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at

http://bugs.php.net/bug.php?id=52245


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


Bug #52245 [Opn]: Private member of parent class accessible from child class.

2010-07-04 Thread phpamid at gmail dot com
Edit report at http://bugs.php.net/bug.php?id=52245&edit=1

 ID:   52245
 User updated by:  phpamid at gmail dot com
 Reported by:  phpamid at gmail dot com
 Summary:  Private member of parent class accessible from child
   class.
 Status:   Open
 Type: Bug
 Package:  *General Issues
 Operating System: Windows 7 x64
 PHP Version:  5.3.2

 New Comment:

as for your code:



class A

{

private $a = "a";

}

class B extends A

{

private $a = "b"; // is this an error?

}



i think every class has own private member, so there is no error.



Ok, I got you.

I hope that this issue will be clarified.

Thank you for discussion.


Previous Comments:

[2010-07-04 14:32:12] giorgio dot liscio at email dot it

in fact if you use protected instead of private it works as expected

but the "private" issue should be clarified, i think



* i'm sorry for the second post


[2010-07-04 14:26:04] giorgio dot liscio at email dot it

sure i know i don't need to override the method with the same one in the
new class to fix this problem



in the parent class the field is private... so theoretically i can not
access the member in the derived class



class A

{

private $a = "a";

}

class B extends A

{

private $a = "b"; // is this an error?

}



it probably is, and maybe php should throw an error


[2010-07-04 14:00:51] phpamid at gmail dot com

.

class Son extends Father{private $x = 'SON';

// try to decomment this:

//public function a(){echo $this->x;}

}

.



I know if I override method a() in the child - everything will be ok,
but it's not necessary to override method a(), because method a() is
inherited form father class and it's public.



p.s. if it's a bug, then it's php behavior.


[2010-07-04 13:50:26] giorgio dot liscio at email dot it

i think that is a bug but i'm not sure if is a php behavior



x;}

}



class Son extends Father{private $x = 'SON';

// try to decomment this:

//public function a(){echo $this->x;}

}



$son_instance = new Son;

$son_instance->a();



?>


[2010-07-04 13:22:18] phpamid at gmail dot com

Description:

my_private_member;

}

}



class Son extends Father {

private $my_private_member = 'Son private member';

}



//After init Son object, it has both private members, we can see it if
we 

var_dump($son_instance);

$son_instance = new Son;



//Following manual php.net the output "Son private member" is expected
here, but 

the result is "Father private member"

$son_instance->show_private_member();

?>

Test script:
---
my_private_member;

}

}



class Son extends Father {

private $my_private_member = 'Son private member';

}



//After init Son object, it has both private members, we can see it if
we var_dump($son_instance);

$son_instance = new Son;



//Following manual php.net the output "Son private member" is expected
here, but the result is "Father private member"

$son_instance->show_private_member();

?>

Expected result:

Expected "Son private member".







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


Bug #52245 [Opn]: Private member of parent class accessible from child class.

2010-07-04 Thread phpamid at gmail dot com
Edit report at http://bugs.php.net/bug.php?id=52245&edit=1

 ID:   52245
 User updated by:  phpamid at gmail dot com
 Reported by:  phpamid at gmail dot com
 Summary:  Private member of parent class accessible from child
   class.
 Status:   Open
 Type: Bug
 Package:  *General Issues
 Operating System: Windows 7 x64
 PHP Version:  5.3.2

 New Comment:

.

class Son extends Father{private $x = 'SON';

// try to decomment this:

//public function a(){echo $this->x;}

}

.



I know if I override method a() in the child - everything will be ok,
but it's not necessary to override method a(), because method a() is
inherited form father class and it's public.



p.s. if it's a bug, then it's php behavior.


Previous Comments:

[2010-07-04 13:50:26] giorgio dot liscio at email dot it

i think that is a bug but i'm not sure if is a php behavior



x;}

}



class Son extends Father{private $x = 'SON';

// try to decomment this:

//public function a(){echo $this->x;}

}



$son_instance = new Son;

$son_instance->a();



?>


[2010-07-04 13:22:18] phpamid at gmail dot com

Description:

my_private_member;

}

}



class Son extends Father {

private $my_private_member = 'Son private member';

}



//After init Son object, it has both private members, we can see it if
we 

var_dump($son_instance);

$son_instance = new Son;



//Following manual php.net the output "Son private member" is expected
here, but 

the result is "Father private member"

$son_instance->show_private_member();

?>

Test script:
---
my_private_member;

}

}



class Son extends Father {

private $my_private_member = 'Son private member';

}



//After init Son object, it has both private members, we can see it if
we var_dump($son_instance);

$son_instance = new Son;



//Following manual php.net the output "Son private member" is expected
here, but the result is "Father private member"

$son_instance->show_private_member();

?>

Expected result:

Expected "Son private member".







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