reflection ?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Sarah Tanembaum

    reflection ?

    Testing reflection in PHP5, but has no luck.

    <?php

    class Foo {
    public $prop;
    function Func($name) {
    echo "Hello $name";
    }
    }
    reflection_clas s::export('Foo' );
    reflection_obje ct::export(new Foo);
    reflection_meth od::export('Foo ', 'func');
    reflection_prop erty::export('F oo', 'prop');
    reflection_exte nsion::export(' standard');
    ?>

    It did not print anything.... Perhaps someone can tell me what I did wrong.

    Thanks


  • Phil Roberts

    #2
    Re: reflection ?

    "Sarah Tanembaum" <sarahtanembaum @yahoo.com> emerged reluctantly
    from the curtain and staggered drunkenly up to the mic. In a
    cracked and slurred voice he muttered:
    [color=blue]
    > Testing reflection in PHP5, but has no luck.
    >
    > <?php
    >
    > class Foo {
    > public $prop;
    > function Func($name) {
    > echo "Hello $name";
    > }
    > }
    > reflection_clas s::export('Foo' );
    > reflection_obje ct::export(new Foo);
    > reflection_meth od::export('Foo ', 'func');
    > reflection_prop erty::export('F oo', 'prop');
    > reflection_exte nsion::export(' standard');
    > ?>
    >
    > It did not print anything.... Perhaps someone can tell me what I
    > did wrong.
    >
    > Thanks
    >
    >
    >[/color]

    I think those early docs are a tad inaccurate.

    Try http://sitten-polizei.de/php/reflect...eflection.html

    --
    Phil Roberts | Deedle Doot Doo Dee Dee | http://www.flatnet.net/

    I could be wrong here, You could be right
    Please forgive me I have sinned - Not on your life
    But that's how you want me, But I'll never fear thee
    Why you and not me? Tell me Holy Man

    Comment

    • Janwillem Borleffs

      #3
      Re: reflection ?

      Phil Roberts wrote:[color=blue][color=green]
      >> reflection_clas s::export('Foo' );
      >> reflection_obje ct::export(new Foo);
      >> reflection_meth od::export('Foo ', 'func');
      >> reflection_prop erty::export('F oo', 'prop');
      >> reflection_exte nsion::export(' standard');[/color][/color]

      The classes have been renamed since RC 3:

      reflection_clas s = reflectionClass
      reflection_obje ct = reflectionObjec t

      etc..


      JW



      Comment

      • Sarah Tanembaum

        #4
        Re: reflection ?

        Thanks, I changed then it works.... but how about this? This seem to fail as
        well.

        Example 14-3. Using the Reflection_Para meter class



        <?php
        function foo($a, $b, $c) { }
        function bar(Exception $a, &$b, $c) { }
        function baz($a= 1, $b= NULL, Reflection_Func tion $c) { }
        function abc() { }

        // Create an instance of Reflection_Func tion with the
        // parameter given from the command line.
        $reflect= new Reflection_Func tion($argv[1]);

        echo $reflect->toString();
        foreach ($reflect->getParameters( ) as $i => $param)
        {
        printf(
        "-- Parameter #%d: %s {\n".
        " Class: %s\n".
        " Allows NULL: %s\n".
        " Passed to by reference: %s\n".
        "}\n",
        $i,
        $param->getName(),
        var_export($par am->getClass(), 1),
        var_export($par am->allowsNull() , 1),
        var_export($par am->isPassedByRefe rence(), 1)
        );
        }
        ?>


        But I just cut and past from the Zend examples
        "Janwillem Borleffs" <jw@jwscripts.c om> wrote in message
        news:4113dd99$0 $18096$4a441750 @news.euronet.n l...[color=blue]
        > Phil Roberts wrote:[color=green][color=darkred]
        > >> reflection_clas s::export('Foo' );
        > >> reflection_obje ct::export(new Foo);
        > >> reflection_meth od::export('Foo ', 'func');
        > >> reflection_prop erty::export('F oo', 'prop');
        > >> reflection_exte nsion::export(' standard');[/color][/color]
        >
        > The classes have been renamed since RC 3:
        >
        > reflection_clas s = reflectionClass
        > reflection_obje ct = reflectionObjec t
        >
        > etc..
        >
        >
        > JW
        >
        >
        >[/color]


        Comment

        • Janwillem Borleffs

          #5
          Re: reflection ?

          Sarah Tanembaum wrote:[color=blue]
          > Thanks, I changed then it works.... but how about this? This seem to
          > fail as well.
          >[/color]

          *ALL* reflection classes have been renamed, so:

          Reflection_Func tion = now ReflectionFunct ion

          (without the underscore)


          JW




          Comment

          • Tim Tyler

            #6
            Re: reflection ?

            Janwillem Borleffs <jw@jwscripts.c om> wrote or quoted:[color=blue]
            > Phil Roberts wrote:[color=green][color=darkred]
            > >> reflection_clas s::export('Foo' );
            > >> reflection_obje ct::export(new Foo);
            > >> reflection_meth od::export('Foo ', 'func');
            > >> reflection_prop erty::export('F oo', 'prop');
            > >> reflection_exte nsion::export(' standard');[/color][/color]
            >
            > The classes have been renamed since RC 3:
            >
            > reflection_clas s = reflectionClass
            > reflection_obje ct = reflectionObjec t
            >
            > etc..[/color]

            It looks like they are trying to follow Java's naming convention:
            camelCase ;-)
            --
            __________
            |im |yler http://timtyler.org/ tim@tt1lock.org Remove lock to reply.

            Comment

            Working...