|
Posted by "Colin Shreffler" on 10/22/05 00:40
I'm not sure this is a problem. I ran the same test and as you say, it
dynamically created a new variable with local scope to the derived (child)
class. I would expect this to happen as it can not access private members
of its base (parent) class.
In your statement:
"But when trying to access this value from the parent class, it is not
there."
Well it shouldn't be. A base class does not know anything about its
derived class's members or methods. Inheritence doesn't work in that
direction. Only derived classes know about their base class members or
methods.
-c
> Today I discovered a possible serious problem with the way the latest
> PHP versions handle private properties.
>
> Given the following code:
>
> <?php
>
> class Base
> {
> private $var1 = 0;
> }
>
> class FinalClass extends Base
> {
>
> function Test()
> {
> $this->var1 = 10;
> }
> }
>
> $c = new FinalClass();
>
> $c->Test();
>
> print_r( $c );
>
> ?>
>
>
> I get the following result:
>
> FinalClass Object
> (
> [var1:private] => 0
> [var1] => 10
> )
>
>
> Now... PHP should have displayed an error when I was trying to set a
> value to this private member from the parent class. No error message was
> displayed. It created a local member which holded the value 10. But when
> trying to access this value from the parent class, it is not there.
>
> I think PHP should notify of the problem but it is not doing so. I have
> my error reporting level on E_ALL.
>
> Any ideas?
>
> Pablo Godel
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
>
Thank you,
Colin Shreffler
Principal
303.349.9010 - cell
928.396.1099 - fax
colin.shreffler@warp9software.com
Warp 9 Software, LLC.
6791 Halifax Avenue
Castle Rock, CO 80104
Confidentiality Notice: The information in this e-mail may be confidential
and/or privileged. This e-mail is intended to be reviewed by only the
individual or organization named in the e-mail address. If you are not the
intended recipient, you are hereby notified that any review, dissemination
or copying of this e-mail and attachments, if any, or the information
contained herein, is strictly prohibited.
Navigation:
[Reply to this message]
|