another parsing problem...

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • otrWalter@gmail.com

    #1

    another parsing problem...

    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?

  • Rik Wasmus

    #2
    Re: another parsing problem...

    On Fri, 09 Nov 2007 17:55:46 +0100, otrWalter@gmail .com
    <otrWalter@gmai l.comwrote:
    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?
    Are you per chance looking for Reflection?

    --
    Rik Wasmus

    Comment

    • Rik Wasmus

      #3
      Re: another parsing problem...

      On Fri, 09 Nov 2007 18:03:29 +0100, Rik Wasmus
      <luiheidsgoeroe @hotmail.comwro te:
      On Fri, 09 Nov 2007 17:55:46 +0100, otrWalter@gmail .com
      <otrWalter@gmai l.comwrote:
      >
      >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

      Comment

      • otrWalter@gmail.com

        #4
        Re: another parsing problem...

        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

        Comment

        • Jerry Stuckle

          #5
          Re: another parsing problem...

          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@attgl obal.net
          =============== ===

          Comment

          • Good Man

            #6
            Re: another parsing problem...

            Jerry Stuckle <jstucklex@attg lobal.netwrote 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($method s as $method) {
            echo methodData($met hod);
            }

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

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

            return $details;

            }

            Comment

            • Jerry Stuckle

              #7
              Re: another parsing problem...

              Good Man wrote:
              Jerry Stuckle <jstucklex@attg lobal.netwrote 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($method s as $method) {
              echo methodData($met hod);
              }
              >
              function methodData(Refl ectionMethod $method) {
              $details = "";
              $name = $method->getName();
              >
              if($method->isPrivate()) {
              $details .= "$name is private<br>";
              }
              if($method->isProtected( )) {
              $details .= "$name is protected<br>";
              }
              if($method->isPublic()) {
              $details .= "$name is public<br>";
              }
              >
              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@attgl obal.net
              =============== ===

              Comment

              • Rik Wasmus

                #8
                Re: another parsing problem...

                On Fri, 09 Nov 2007 19:31:34 +0100, Good Man <heyho@letsgo.c omwrote:
                Jerry Stuckle <jstucklex@attg lobal.netwrote 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

                Comment

                • Rik Wasmus

                  #9
                  Re: another parsing problem...

                  On Fri, 09 Nov 2007 18:42:49 +0100, otrWalter@gmail .com
                  <otrWalter@gmai l.comwrote:
                  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.
                  Well, you shouldn't want it :P
                  If you do however use print_r, it's a simple matter of parsing the output.
                  Maybe applying strtok() could simplify processing/provide some shortcuts
                  though.

                  Or build your own PHP: in <http://bugs.php.net/bug.php?id=3781 6it is
                  referenced where Reflection is blocked from displaying it, see:
                  <http://cvs.php.net/viewvc.cgi/php-src/ext/reflection/php_reflection. c?r1=1.185&r2=1 .186>.
                  So just alter the php_reflection. c file to your needs :P.
                  --
                  Rik Wasmus

                  Comment

                  • Good Man

                    #10
                    Re: another parsing problem...

                    "Rik Wasmus" <luiheidsgoeroe @hotmail.comwro te in
                    news:op.t1jftpp e5bnjuv@metalli um.lan:
                    On Fri, 09 Nov 2007 19:31:34 +0100, Good Man <heyho@letsgo.c omwrote:
                    >
                    >Jerry Stuckle <jstucklex@attg lobal.netwrote 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.

                    Comment

                    • otrWalter@gmail.com

                      #11
                      Re: another parsing problem...

                      On Nov 9, 6:31 pm, Good Man <he...@letsgo.c omwrote:
                      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

                      Comment

                      • otrWalter@gmail.com

                        #12
                        Re: another parsing problem...

                        On Nov 9, 6:47 pm, "Rik Wasmus" <luiheidsgoe... @hotmail.comwro te:
                        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

                        Comment

                        • otrWalter@gmail.com

                          #13
                          Re: another parsing problem...

                          On Nov 9, 6:48 pm, "Rik Wasmus" <luiheidsgoe... @hotmail.comwro te:
                          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

                          Comment

                          • AnrDaemon

                            #14
                            Re: another parsing problem...

                            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 <anrdaemon@free mail.ru>

                            Comment

                            Working...