|
Posted by Jerry Stuckle on 09/18/07 01:32
Yarco wrote:
> You are talking something related to pure OO.
> In my eyes, php4 just look like c, and php5 look like c++. And i like c
> ++. Because no strict rule said you did it right or wrong.
> OO is designed to prevent access to the private members, but not
> saying we don't need to access that in sometimes. That's why c++ need
> friend class/function i think.
> If reflection is only a way to discover the public members, it could
> be designed as a php class(in phplib or zend framework).
> So it should do something that you can't use php function to do in
> that it is done in c.(That is accessing private members.)
>
> On Sep 17, 7:56 pm, Jerry Stuckle <jstuck...@attglobal.net> wrote:
>> Yarco wrote:
>>> On Sep 13, 7:27 pm, Jerry Stuckle <jstuck...@attglobal.net> wrote:
>>>> Yarco wrote:
>>>>> On Sep 12, 8:13 pm, Jerry Stuckle <jstuck...@attglobal.net> wrote:
>>>>>> Yarco wrote:
>>>>>>> For example:
>>>>>>> <?php
>>>>>>> class Test
>>>>>>> {
>>>>>>> private $name = 'yarco';
>>>>>>> }
>>>>>>> $p = new ReflectionPropery('Test', 'name');
>>>>>>> print $p->getValue();
>>>>>>> ?>
>>>>>>> This won't work. See:http://www.php.net/manual/en/language.oop5.reflection.php
>>>>>>> ==================
>>>>>>> Note: Trying to get or set private or protected class property's
>>>>>>> values will result in an exception being thrown.
>>>>>>> ==================
>>>>>>> But when we use print_r or var_dump, we could see the private member.
>>>>>>> Why reflection doesn't support this?
>>>>>>> (We have friend class in c++.)
>>>>>> Because that's the way it works. And there are no friend classes in PHP.
>>>>>> If you want the value of a private variable, you need a non-private
>>>>>> method to get it.
>>>>>> And I suspect the allow print_r() and var_dump() to display the values
>>>>>> because those are debugging aids, while reflection isn't necessarily.
>>>> > But when i think of Reflection, it is a method to view everything in
>>>> > an object(member's type and value).
>>>> > If it doesn't support private member, we already have such functions
>>>> > like get_class_XXX...no need reflection.
>>>> (Top posting fixed)
>>>> That's not what reflection is in OO design. PHP has it right.
>>>> Reflection allows you to look at a class and see what is *publicly*
>>>> available. It is not meant to break encapsulation.
>>>> P.S. Please don't top post. Thanks.
>>>> --
>>>> ==================
>>>> Remove the "x" from my email address
>>>> Jerry Stuckle
>>>> JDS Computer Training Corp.
>>>> jstuck...@attglobal.net
>>>> ==================
>> > I think steve is right.
>> > But i don't agree with Jerry:
>> >> Reflection allows you to look at a class and see what is *publicly*
>> >> available. It is not meant to break encapsulation.
>> > Reflection should access private members.Or we won't need such a core
>> > feature in php.
>> >
>> (top posting fixed)
>>
>> No, encapsulation is one of the basic tenets of both Object Based and
>> Object Oriented programming. Properly implemented, it provides
>> protection for those members of the class.
>>
>> Reflection is not meant to be a way to break that tenet. Rather, it is
>> a way to discover the *publicly available* members. To allow reflection
>> to access private members would break that tenet and potentially cause
>> problems OO is designed to prevent. This is true in all OO languages
>> where reflections is available.
>>
>> So, whether you agree with me or not is immaterial. The way it is
>> implemented in PHP matches OO concepts and other languages where
>> reflection is used.
>>
>> Also, top posting is posting your message before the message you're
>> replying to. This newsgroup (and most of usenet) posts responses after
>> the message they are responding to.
>>
>> --
>> ==================
>> Remove the "x" from my email address
>> Jerry Stuckle
>> JDS Computer Training Corp.
>> jstuck...@attglobal.net
>> ==================
>
>
You are talking something related to pure OO.
In my eyes, php4 just look like c, and php5 look like c++. And i like c
++. Because no strict rule said you did it right or wrong.
OO is designed to prevent access to the private members, but not
saying we don't need to access that in sometimes. That's why c++ need
friend class/function i think.
If reflection is only a way to discover the public members, it could
be designed as a php class(in phplib or zend framework).
So it should do something that you can't use php function to do in
that it is done in c.(That is accessing private members.)
(Top posting fixed again)
No, PHP 4 is also OO - not as much as PHP5, but still OO. And private
members how encapsulation is implemented, which is strictly object based
or object oriented.
C, for instance, has no "public", "private" or "protected" keywords.
C++ does. So does Java.
If you need that access, you need to create accessor functions.
Reflection will not do it for you. And yes, C++ does have friend
classes and functions - but even Bjorn Stroustrop admits they are a
"necessary evil" - not a choice.
So, reflection is only a means of discovering public members. And since
C doesn't have private members, reflection doesn't find private members.
In fact, since C doesn't even have classes, there is nothing for
reflection to do - it is not applicable in C.
And once again, please don't top post. If you continue top posting, you
will generally find yourself persona not grata in this newsgroup.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================
Navigation:
[Reply to this message]
|