another parsing problem...

another parsing problem...

am 09.11.2007 17:55:46 von otrWalter

I'm trying to display that type, name and value to class properties.
Yes, I know about print_r().

I'm just trying to build a display format for this information. AFAIK,
the standard PHP tools to look into classes do not give you PRIVATE
and PROTECTED properties (nor methods), but the print_r() does! (At
least for properties it does.)

This this display below...

// [this is a stored in a string variable]
Vegetable Object
(
[edible:private] => spinach
[color:protected] => green
[size] => 1
)

Now, I'd like to parse this string (above) into 3 arrays:
1) Public
2) Private
3) Protected

Each having a list of variables names with their values, as so...

array
(
[private] => ([edible] => spinach),
[protected] => ([color] => green),
[public] => ([size] => 1)
}

Any ideas?

thanks

walter

PS: Any one know how to get the list of PRIVATE and PROTECTED methods
from a class? Without parsing the actual file?

Re: another parsing problem...

am 09.11.2007 18:03:29 von luiheidsgoeroe

On Fri, 09 Nov 2007 17:55:46 +0100, otrWalter@gmail.com =

wrote:

> I'm trying to display that type, name and value to class properties.
> Yes, I know about print_r().
>
> I'm just trying to build a display format for this information. AFAIK,=

> the standard PHP tools to look into classes do not give you PRIVATE
> and PROTECTED properties (nor methods), but the print_r() does! (At
> least for properties it does.)
>
> This this display below...
>
> // [this is a stored in a string variable]
> Vegetable Object
> (
> [edible:private] =3D> spinach
> [color:protected] =3D> green
> [size] =3D> 1
> )
>
> Now, I'd like to parse this string (above) into 3 arrays:
> 1) Public
> 2) Private
> 3) Protected
>
> Each having a list of variables names with their values, as so...
>
> array
> (
> [private] =3D> ([edible] =3D> spinach),
> [protected] =3D> ([color] =3D> green),
> [public] =3D> ([size] =3D> 1)
> }
>
> Any ideas?

Are you per chance looking for Reflection?
http://nl2.php.net/oop5.reflection
-- =

Rik Wasmus

Re: another parsing problem...

am 09.11.2007 18:26:37 von luiheidsgoeroe

On Fri, 09 Nov 2007 18:03:29 +0100, Rik Wasmus
wrote:

> On Fri, 09 Nov 2007 17:55:46 +0100, otrWalter@gmail.com
> wrote:
>
>> I'm trying to display that type, name and value to class properties.
>> Yes, I know about print_r().
>>
>> I'm just trying to build a display format for this information. AFAIK,
>> the standard PHP tools to look into classes do not give you PRIVATE
>> and PROTECTED properties (nor methods), but the print_r() does! (At
>> least for properties it does.)

> Are you per chance looking for Reflection?
> http://nl2.php.net/oop5.reflection

Nevermind, you can't get the private/protected variable values with it,
only their existance/properties.
--
Rik Wasmus

Re: another parsing problem...

am 09.11.2007 18:42:49 von otrWalter

> > Are you per chance looking for Reflection?
> >http://nl2.php.net/oop5.reflection

Why yes! I am! But...


> Nevermind, you can't get the private/protected variable values with it,
> only their existance/properties.
> --
> Rik Wasmus

he he.

Yes, reflection doesn't quite do what I want, thus my tack on using
'print_r()' and parsing the resulting string.

Next! ;)

Thanks

Walter

Re: another parsing problem...

am 09.11.2007 19:07:12 von Jerry Stuckle

otrWalter@gmail.com wrote:
> I'm trying to display that type, name and value to class properties.
> Yes, I know about print_r().
>
> I'm just trying to build a display format for this information. AFAIK,
> the standard PHP tools to look into classes do not give you PRIVATE
> and PROTECTED properties (nor methods), but the print_r() does! (At
> least for properties it does.)
>
> This this display below...
>
> // [this is a stored in a string variable]
> Vegetable Object
> (
> [edible:private] => spinach
> [color:protected] => green
> [size] => 1
> )
>
> Now, I'd like to parse this string (above) into 3 arrays:
> 1) Public
> 2) Private
> 3) Protected
>
> Each having a list of variables names with their values, as so...
>
> array
> (
> [private] => ([edible] => spinach),
> [protected] => ([color] => green),
> [public] => ([size] => 1)
> }
>
> Any ideas?
>
> thanks
>
> walter
>
> PS: Any one know how to get the list of PRIVATE and PROTECTED methods
> from a class? Without parsing the actual file?
>
>

No, that's the whole purpose of PRIVATE and PROTECTED members. If you
want to list them, you need the code as a class member.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

Re: another parsing problem...

am 09.11.2007 19:31:34 von Good Man

Jerry Stuckle wrote in news:ZOidnXa6r-
RzPKnanZ2dnUVZ_uLinZ2d@comcast.com:

>> PS: Any one know how to get the list of PRIVATE and PROTECTED methods
>> from a class? Without parsing the actual file?
>>
>>
>
> No, that's the whole purpose of PRIVATE and PROTECTED members. If you
> want to list them, you need the code as a class member.


Hiya...

I'm in the middle of learning OO programming, and probably not the
person to offer solutions, but perhaps I can use this moment to ask if
the following is a solution to his PS? And if it's not, perhaps someone
can explain to me why?

Let's say his class name is 'Veggie'

**

$prod_class = new ReflectionClass( 'Veggie' );
$methods = $prod_class->getMethods();

foreach($methods as $method) {
echo methodData($method);
}

function methodData(ReflectionMethod $method) {
$details = "";
$name = $method->getName();

if($method->isPrivate()) {
$details .= "$name is private
";
}
if($method->isProtected()) {
$details .= "$name is protected
";
}
if($method->isPublic()) {
$details .= "$name is public
";
}

return $details;

}

Re: another parsing problem...

am 09.11.2007 19:44:47 von Jerry Stuckle

Good Man wrote:
> Jerry Stuckle wrote in news:ZOidnXa6r-
> RzPKnanZ2dnUVZ_uLinZ2d@comcast.com:
>
>>> PS: Any one know how to get the list of PRIVATE and PROTECTED methods
>>> from a class? Without parsing the actual file?
>>>
>>>
>> No, that's the whole purpose of PRIVATE and PROTECTED members. If you
>> want to list them, you need the code as a class member.
>
>
> Hiya...
>
> I'm in the middle of learning OO programming, and probably not the
> person to offer solutions, but perhaps I can use this moment to ask if
> the following is a solution to his PS? And if it's not, perhaps someone
> can explain to me why?
>
> Let's say his class name is 'Veggie'
>
> **
>
> $prod_class = new ReflectionClass( 'Veggie' );
> $methods = $prod_class->getMethods();
>
> foreach($methods as $method) {
> echo methodData($method);
> }
>
> function methodData(ReflectionMethod $method) {
> $details = "";
> $name = $method->getName();
>
> if($method->isPrivate()) {
> $details .= "$name is private
";
> }
> if($method->isProtected()) {
> $details .= "$name is protected
";
> }
> if($method->isPublic()) {
> $details .= "$name is public
";
> }
>
> return $details;
>
> }
>
>

That gives the names, etc. of methods. But not the values of the class
variables - which is what he wants.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

Re: another parsing problem...

am 09.11.2007 19:47:39 von luiheidsgoeroe

On Fri, 09 Nov 2007 19:31:34 +0100, Good Man wrote:

> Jerry Stuckle wrote in news:ZOidnXa6r-
> RzPKnanZ2dnUVZ_uLinZ2d@comcast.com:
>
>>> PS: Any one know how to get the list of PRIVATE and PROTECTED methods
>>> from a class? Without parsing the actual file?
>>>
>>>
>>
>> No, that's the whole purpose of PRIVATE and PROTECTED members. If you
>> want to list them, you need the code as a class member.
>
>
> Hiya...
>
> I'm in the middle of learning OO programming, and probably not the
> person to offer solutions, but perhaps I can use this moment to ask if
> the following is a solution to his PS? And if it's not, perhaps someone
> can explain to me why?

It is no solution to his problem because he wants the display the _value_
of a private/protected variable. That's simply not possible with PHP
Reflection.
--
Rik Wasmus

Re: another parsing problem...

am 09.11.2007 19:48:06 von luiheidsgoeroe

On Fri, 09 Nov 2007 18:42:49 +0100, otrWalter@gmail.com =

wrote:
>> > Are you per chance looking for Reflection?
>> >http://nl2.php.net/oop5.reflection
>
> Why yes! I am! But...
>
>
>> Nevermind, you can't get the private/protected variable values with i=
t,
>> only their existance/properties.
>> --
>> Rik Wasmus
>
> he he.
>
> Yes, reflection doesn't quite do what I want, thus my tack on using
> 'print_r()' and parsing the resulting string.

Well, you shouldn't want it :P
If you do however use print_r, it's a simple matter of parsing the outpu=
t. =

Maybe applying strtok() could simplify processing/provide some shortcuts=
=

though.

Or build your own PHP: in it is=
=

referenced where Reflection is blocked from displaying it, see: =

1=3D1.185&r2=3D1.186>. =

So just alter the php_reflection.c file to your needs :P.
-- =

Rik Wasmus

Re: another parsing problem...

am 09.11.2007 20:36:45 von Good Man

"Rik Wasmus" wrote in
news:op.t1jftppe5bnjuv@metallium.lan:

> On Fri, 09 Nov 2007 19:31:34 +0100, Good Man wrote:
>
>> Jerry Stuckle wrote in news:ZOidnXa6r-
>> RzPKnanZ2dnUVZ_uLinZ2d@comcast.com:
>>
>>>> PS: Any one know how to get the list of PRIVATE and PROTECTED
>>>> methods from a class? Without parsing the actual file?
>>>>
>>>>
>>>
>>> No, that's the whole purpose of PRIVATE and PROTECTED members. If
>>> you want to list them, you need the code as a class member.
>>
>>
>> Hiya...
>>
>> I'm in the middle of learning OO programming, and probably not the
>> person to offer solutions, but perhaps I can use this moment to ask
>> if the following is a solution to his PS? And if it's not, perhaps
>> someone can explain to me why?
>
> It is no solution to his problem because he wants the display the
> _value_ of a private/protected variable. That's simply not possible
> with PHP Reflection.

Right, but I interpreted his "PS" as a different request, one that simply
was a list of private and protected methods, with no mention of values.

Re: another parsing problem...

am 09.11.2007 23:32:04 von otrWalter

On Nov 9, 6:31 pm, Good Man wrote:
> Let's say his class name is 'Veggie'

What a beautiful piece of work.

I read and re-read the reflection dox and just didn't grok it.

1 down, 1 to go.

Thx a lot!

Walter

Re: another parsing problem...

am 09.11.2007 23:33:29 von otrWalter

On Nov 9, 6:47 pm, "Rik Wasmus" wrote:

> It is no solution to his problem because he wants the display the _value_
> of a private/protected variable. That's simply not possible with PHP
> Reflection.

Right, thus my query on parsing the return string form 'print_r()'

walter

Re: another parsing problem...

am 09.11.2007 23:36:31 von otrWalter

On Nov 9, 6:48 pm, "Rik Wasmus" wrote:
> On Fri, 09 Nov 2007 18:42:49 +0100, otrWal...@gmail.com
>
> Well, you shouldn't want it :P

LOL, yes, well, I'm told that alot, about a lot of things! But it
doesn't stop me from asking.


> If you do however use print_r, it's a simple matter of parsing the output.

That's what I'm thinking, but I don't see a simple solution to parse
that string



> Maybe applying strtok() could simplify processing/provide some shortcuts
> though.

mmm, I'll look that up.


> Or build your own PHP:

that doesn't help with the "generic" variable display tool I'm
expanding on, but thanks!

Walter

Re: another parsing problem...

am 11.11.2007 12:25:00 von AnrDaemon

Greetings, otrWalter@gmail.com.
In reply to Your message dated Friday, November 9, 2007, 19:55:46,

> I'm trying to display that type, name and value to class properties.
> Yes, I know about print_r().

> I'm just trying to build a display format for this information. AFAIK,
> the standard PHP tools to look into classes do not give you PRIVATE
> and PROTECTED properties (nor methods), but the print_r() does! (At
> least for properties it does.)

> This this display below...

> // [this is a stored in a string variable]
> Vegetable Object
> (
> [edible:private] => spinach
> [color:protected] => green
> [size] => 1
> )

> Now, I'd like to parse this string (above) into 3 arrays:
> 1) Public
> 2) Private
> 3) Protected

> Each having a list of variables names with their values, as so...

> array
> (
> [private] => ([edible] => spinach),
> [protected] => ([color] => green),
> [public] => ([size] => 1)
> }

> Any ideas?

$c = print_r($object, true);

Then work over $c.


--
Sincerely Yours, AnrDaemon