FAQ
I have the first draft of PHP 5 reflection API ready. You can find it
at:

http://www.gravitonic.com/software/php/reflection.txt

Comments and suggestions are appreciated.

-Andrei http://www.gravitonic.com/

"Beware of bugs in the above code; I have only proved it correct,
not tried it." -- Donald Knuth

Search Discussions

  • Marcus Börger at Mar 29, 2003 at 9:00 pm

    At 21:37 29.03.2003, Andrei Zmievski wrote:
    I have the first draft of PHP 5 reflection API ready. You can find it
    at:

    http://www.gravitonic.com/software/php/reflection.txt

    Comments and suggestions are appreciated.

    What about doing it with some interfaces?

    marcus
  • Andrei Zmievski at Mar 29, 2003 at 9:10 pm

    On Sat, 29 Mar 2003, Marcus Börger wrote:
    http://www.gravitonic.com/software/php/reflection.txt

    Comments and suggestions are appreciated.

    What about doing it with some interfaces?
    Why?

    -Andrei http://www.gravitonic.com/
    * Software never has bugs. It just develops random features. *
  • Marcus Börger at Mar 29, 2003 at 9:18 pm

    At 22:09 29.03.2003, Andrei Zmievski wrote:
    On Sat, 29 Mar 2003, Marcus Börger wrote:
    http://www.gravitonic.com/software/php/reflection.txt

    Comments and suggestions are appreciated.

    What about doing it with some interfaces?
    or an abstract base class because most methods are the same

    marcus
  • Andrei Zmievski at Mar 29, 2003 at 9:19 pm

    On Sat, 29 Mar 2003, Marcus Börger wrote:
    What about doing it with some interfaces?
    or an abstract base class because most methods are the same
    Doing it just for the sake of interface or abstract classes doesn't seem
    prudent to me. So what if some methods are duplicated?

    -Andrei http://www.gravitonic.com/

    As I was going up the stair, I met a man who wasn't there.
    He wasn't there again today. I wish, I wish he'd stay away.
    -Hughes Mearns
  • Andi Gutmans at Mar 30, 2003 at 6:43 pm

    At 04:19 PM 3/29/2003 -0500, Andrei Zmievski wrote:
    On Sat, 29 Mar 2003, Marcus Börger wrote:
    What about doing it with some interfaces?
    or an abstract base class because most methods are the same
    Doing it just for the sake of interface or abstract classes doesn't seem
    prudent to me. So what if some methods are duplicated?

    I agree with Andrei.

    Andi
  • Timm Friebe at Mar 29, 2003 at 9:28 pm

    On Sat, 2003-03-29 at 21:37, Andrei Zmievski wrote:
    I have the first draft of PHP 5 reflection API ready. You can find it
    at:

    http://www.gravitonic.com/software/php/reflection.txt

    Comments and suggestions are appreciated.
    * ClassType::getMethods([int flags]);

    I assume flags is a bitfield of private, public, protected, final
    and so on, defaulting to all of them?

    - Timm
  • Andrei Zmievski at Mar 29, 2003 at 9:35 pm

    On Sat, 29 Mar 2003, Timm Friebe wrote:
    I have the first draft of PHP 5 reflection API ready. You can find it
    at:

    http://www.gravitonic.com/software/php/reflection.txt

    Comments and suggestions are appreciated.
    * ClassType::getMethods([int flags]);

    I assume flags is a bitfield of private, public, protected, final
    and so on, defaulting to all of them?
    Something like that. I haven't finalized what kind of method searching
    will be available. Perhaps one of the flags will be REGEXP with a
    optional argument specifying the regexp to match method name against.

    -Andrei http://www.gravitonic.com/

    "Beware of bugs in the above code; I have only proved it correct,
    not tried it." -- Donald Knuth
  • Andi Gutmans at Mar 30, 2003 at 4:13 am

    At 04:34 PM 3/29/2003 -0500, Andrei Zmievski wrote:
    On Sat, 29 Mar 2003, Timm Friebe wrote:
    I have the first draft of PHP 5 reflection API ready. You can find it
    at:

    http://www.gravitonic.com/software/php/reflection.txt

    Comments and suggestions are appreciated.
    * ClassType::getMethods([int flags]);

    I assume flags is a bitfield of private, public, protected, final
    and so on, defaulting to all of them?
    Something like that. I haven't finalized what kind of method searching
    will be available. Perhaps one of the flags will be REGEXP with a
    optional argument specifying the regexp to match method name against.
    I would keep it simple. I don't see much use in regexp and I think if
    needed this is something to be done in user-land.

    Andi
  • Andrei Zmievski at Mar 30, 2003 at 3:43 pm

    On Sun, 30 Mar 2003, Andi Gutmans wrote:
    Something like that. I haven't finalized what kind of method searching
    will be available. Perhaps one of the flags will be REGEXP with a
    optional argument specifying the regexp to match method name against.
    I would keep it simple. I don't see much use in regexp and I think if
    needed this is something to be done in user-land.
    Okay. One issue that I'm struggling with, though, is whether to roll the
    functionality of Zend built-in functions, such get_class(),
    get_class_methods(), etc, into the reflection API. Those function return
    simple strings or arrays and most of the time that is enough. Do you
    think we should have both ways of obtaining information in the new
    reflection API, getMethods() that will return an array of MethodTypes
    and something like getMethodsSimple() that will do what get_methods()
    does?

    -Andrei http://www.gravitonic.com/
    * Anything will fit if you push hard enough. *
  • Andi Gutmans at Mar 30, 2003 at 6:27 pm

    At 10:42 AM 3/30/2003 -0500, Andrei Zmievski wrote:
    On Sun, 30 Mar 2003, Andi Gutmans wrote:
    Something like that. I haven't finalized what kind of method searching
    will be available. Perhaps one of the flags will be REGEXP with a
    optional argument specifying the regexp to match method name against.
    I would keep it simple. I don't see much use in regexp and I think if
    needed this is something to be done in user-land.
    Okay. One issue that I'm struggling with, though, is whether to roll the
    functionality of Zend built-in functions, such get_class(),
    get_class_methods(), etc, into the reflection API. Those function return
    simple strings or arrays and most of the time that is enough. Do you
    think we should have both ways of obtaining information in the new
    reflection API, getMethods() that will return an array of MethodTypes
    and something like getMethodsSimple() that will do what get_methods()
    does?
    I think it should be getMethods() only which returns MethodTypes which in
    turn has invoke() and getName() methods.
  • Alan Knowles at Mar 30, 2003 at 2:05 am
    A few more ideas for it:)

    - If you stored token start/end then you would be able to do getSource
    for function/method/class.. etc.. (which can do a load file/tokenizer
    and return implode('',array_range(starttoken,endtoken)
    - and add the generic methods
    loadTokens(); and freeTokens(); so that memory can be managed reasonably
    for them..
    * it may also be better to store the token of the doc comment - On some
    of the pear classes the comment code is larger than the PHP code, and
    would be quite an overhead... - just make it throw an exception if you
    forgot to load the tokens for it..

    - there appears to be no arguments array for methods/functions

    - not sure if extendsClass(), would be implemented by Implements?, and
    theres no getExtendsArray(), to return the tree of extends

    - constructors: -
    $classdetails = new ClassType('myclass');
    $classdetails = new ClassType($this);
    rather than
    $classdetails = ClassType::fromName('myclass')
    $classdetails = ClassType::fromInstance('myclass')

    - I still think it would be nice to implement some of them as variables
    so that
    print_r($classdetails); would display some cute output...




    btw - It would also be nice to have unloadclass - so
    a) the codedoc generators - could load and free classes.
    b) php-gtk could reload modules rather than having to restart each time
    to test code..

    Regards
    Alan


    Andrei Zmievski wrote:
    I have the first draft of PHP 5 reflection API ready. You can find it
    at:

    http://www.gravitonic.com/software/php/reflection.txt

    Comments and suggestions are appreciated.

    -Andrei http://www.gravitonic.com/

    "Beware of bugs in the above code; I have only proved it correct,
    not tried it." -- Donald Knuth

  • Andrei Zmievski at Mar 31, 2003 at 8:53 pm

    On Sun, 30 Mar 2003, Alan Knowles wrote:
    - If you stored token start/end then you would be able to do getSource
    for function/method/class.. etc.. (which can do a load file/tokenizer
    and return implode('',array_range(starttoken,endtoken)
    Keeping track of the tokens this way would require quite some code, I
    think.
    * it may also be better to store the token of the doc comment - On some
    of the pear classes the comment code is larger than the PHP code, and
    would be quite an overhead... - just make it throw an exception if you
    forgot to load the tokens for it..
    Hmm, I see the point, but is that really a problem? If a lot of people
    are worried about the overhead of storing doc comments, we could perhaps
    store only the starting/ending line of the comment and let the other
    tools extract them. But it means that the tools have to have access to
    the original source file - not really possible with 3rd party software
    distributed under an encoder, for example.
    - there appears to be no arguments array for methods/functions
    No really good way of doing it with the current architecture. I defer to
    Andi/Zeev to see if it's possible to capture the declared parameters
    somehow..
    - not sure if extendsClass(), would be implemented by Implements?, and
    theres no getExtendsArray(), to return the tree of extends
    What would extendsClass() do?
    - constructors: -
    $classdetails = new ClassType('myclass');
    $classdetails = new ClassType($this);
    rather than
    $classdetails = ClassType::fromName('myclass')
    $classdetails = ClassType::fromInstance('myclass')
    I'd rather avoid overloading. And in this case, these methods are
    basically factories.
    - I still think it would be nice to implement some of them as variables
    so that
    print_r($classdetails); would display some cute output...
    We could always have toString() method for each one..
    btw - It would also be nice to have unloadclass - so
    a) the codedoc generators - could load and free classes.
    b) php-gtk could reload modules rather than having to restart each time
    to test code..
    What do you mean by unloadclass?

    -Andrei http://www.gravitonic.com/

    "This isn't right. This isn't even wrong."
    -- Wolfgang Pauli
  • Sebastian Bergmann at Apr 1, 2003 at 7:09 am

    Andrei Zmievski wrote:
    What do you mean by unloadclass?
    I think what the name suggests: unload a class, ie. undeclare it.
  • Andi Gutmans at Mar 30, 2003 at 6:43 pm

    At 03:37 PM 3/29/2003 -0500, Andrei Zmievski wrote:
    I have the first draft of PHP 5 reflection API ready. You can find it
    at:

    http://www.gravitonic.com/software/php/reflection.txt

    Comments and suggestions are appreciated.
    By the way, I might have missed it,but maybe we should have a way to check
    if the method was defined in the specific class or if it is inherited.

    Andi
  • Jon Parise at Mar 30, 2003 at 7:53 pm

    On Sat, Mar 29, 2003 at 03:37:30PM -0500, Andrei Zmievski wrote:

    I have the first draft of PHP 5 reflection API ready. You can find it
    at:

    http://www.gravitonic.com/software/php/reflection.txt

    Comments and suggestions are appreciated.
    It would be cool if there was a way to get the (defined) set of
    parameters for a function / method. I'm going to assume that, because
    it's not included in your proposal, it's not currently possible given
    the current model, though.

    --
    Jon Parise (jon@php.net) :: The PHP Project (http://www.php.net/)
  • Andrei Zmievski at Mar 30, 2003 at 8:50 pm

    On Sun, 30 Mar 2003, Jon Parise wrote:
    It would be cool if there was a way to get the (defined) set of
    parameters for a function / method. I'm going to assume that, because
    it's not included in your proposal, it's not currently possible given
    the current model, though.
    Right. The engine would need to be modified in order to keep track of
    that.

    -Andrei http://www.gravitonic.com/

    "Everything should be made as simple
    as possible, but not simpler."
    -- Albert Einstein
  • Tomica Jovanovic at Apr 8, 2003 at 8:53 am
    hi!
    I have the first draft of PHP 5 reflection API ready. You can find it at:

    http://www.gravitonic.com/software/php/reflection.txt

    Comments and suggestions are appreciated.
    First of all, why isn't InterfaceType base class for ClassType, since,
    in fact, class _is_ an interface, and every method of InterfaceType is
    in fact present in the ClassType (except for the getParentInterface()
    which is named getParentClass in ClassType, but could easily be named
    getParent in both classes, or the getParentInterface() could be
    "non-virtual" in the InterfaceType class...)

    Second, why aren't some of the methods from ClassType available in the
    InterfaceType, when they are clearly valid there. Some of them include:

    class InterfaceType {

    // ... that suggested stuff in RFC
    // and my stuff below


    // same as ClassType::getInterfaces()
    // but not sure about this one.. didn't really understand if
    // Interface can "implement", or extend more than one
    // Interface... (and BTW, if they cant, they should ;)
    function getInterfaces();

    // same as ClassType::hasInterface($name)
    // look the note in the previous method
    function hasInterface($name);


    // same as ClassType::getModifiers()
    // the RFC states "currently only ABSTRACT" which doesn't apply
    // to Interfaces, but might be usable later when/if more
    // modifiers are added
    function getModifiers();


    // same as ClassType::isInstanceOf()
    // but with a slightly different meaning. it would return if $obj is
    // an instance of a Class that implements this Interface (and
    // thus, can safely be looked at as an "instance" of this Interface)
    function isInstanceOf($obj);


    // same as ClassType::invokeMethod()
    function invokeMethod($name, $obj, $params);

    } // end InterfaceType


    that's it for now..


    - zombie - Tomica Jovanovic - tomica@mbox.co.yu

    * As we anarchists say: There's no government like no government.
  • Andrei Zmievski at Apr 8, 2003 at 3:10 pm

    On Tue, 08 Apr 2003, Tomica Jovanovic wrote:
    First of all, why isn't InterfaceType base class for ClassType, since,
    in fact, class _is_ an interface, and every method of InterfaceType is
    in fact present in the ClassType (except for the getParentInterface()
    which is named getParentClass in ClassType, but could easily be named
    getParent in both classes, or the getParentInterface() could be
    "non-virtual" in the InterfaceType class...)
    True. I'll think about having ClassTypep inherit from InterfaceType.
    Second, why aren't some of the methods from ClassType available in the
    InterfaceType, when they are clearly valid there. Some of them include:

    class InterfaceType {

    // same as ClassType::getInterfaces()
    // but not sure about this one.. didn't really understand if
    // Interface can "implement", or extend more than one
    // Interface... (and BTW, if they cant, they should ;)
    function getInterfaces();
    Doesn't make sense. An interface can extend only one interface.
    // same as ClassType::hasInterface($name)
    // look the note in the previous method
    function hasInterface($name);
    See above.
    // same as ClassType::getModifiers()
    // the RFC states "currently only ABSTRACT" which doesn't apply
    // to Interfaces, but might be usable later when/if more
    // modifiers are added
    function getModifiers();
    Interfaces don't have any modifiers.
    // same as ClassType::isInstanceOf()
    // but with a slightly different meaning. it would return if $obj is
    // an instance of a Class that implements this Interface (and
    // thus, can safely be looked at as an "instance" of this Interface)
    function isInstanceOf($obj);
    I guess this would be nice.

    -Andrei http://www.gravitonic.com/

    If you find a job that you love, you'll
    never work another day in your life.
    - Mark Jackson

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupphp-internals @
categoriesphp
postedMar 29, '03 at 8:38p
activeApr 8, '03 at 3:10p
posts19
users8
websitephp.net

People

Translate

site design / logo © 2022 Grokbase