The PHP Language Workbench

Loading...

Flash Player 9 (or above) is needed to view presentations.
We have detected that you do not have it on your computer. To install it, go here.

0 comments

Post a comment

    Post a comment
    Embed Video
    Edit your comment Cancel

    Notes on slide 1

    Theme created by Sakari Koivunen and Henrik Omma Released under the LGPL license.

    2 Favorites

    The PHP Language Workbench - Presentation Transcript

    1. Welcome!
        • PECL
        • The PHP Language Workbench
        • Sebastian Bergmann
        • http://sebastian-bergmann.de/
        • March 13 th 2008
    2. Who I am
      • Sebastian Bergmann
      • Involved in the PHP Project since 2000
      • Author, Consultant, Coach, Trainer
      • Developer for eZ Systems AS
    3. Who are you?
      • Your experience with
        • PHP 5?
        • PECL?
        • Meta Programming?
        • AOP?
    4. PHP Language Extensions
      • PECL has extensions that
        • add “normal” functionality to PHP and/or
        • are “not so normal”
          • Operator
          • VLD
          • Parsekit
          • Parse Tree
          • Runkit
          • Intercept
    5. ext/operator
      • Operator Overloading
      • C++, for instance, allows to overload operators such as + , - , * and /
      • The programmer can decide on the semantics of these operators on a class-by-class basis
      • Goal: Make the code more readable
    6. ext/operator
      • +
      • -
      • *
      • /
      • %
      • <<
      • >>
      • .
      • .=
      • |
      • &
      • ^
      • ~
      • !
      • ++
      • --
      • +=
      • -=
      • *=
      • /=
      • %=
      • <<=
      • >>=
      • |=
      • &=
      • ^=
      • ~=
      • ===
      • !==
      • ==
      • !=
      • <
      • <=
      • >
      • >=
    7. ext/operator <?php class Fraction { public $numerator ; public $denominator ; public function __construct ( $n , $d = 1 ) { $this -> numerator = $n ; $this -> denominator = $d ; } } ?>
    8. ext/operator <?php class Fraction { // ... public function __toString () { return $this -> numerator . '/' . $this -> denominator ; } } ?>
    9. ext/operator <?php class Fraction { // ... public function __add ( Fraction $fraction ) { return new Fraction ( $this -> numerator * $fraction -> denominator + $fraction -> numerator * $this -> denominator , $this -> denominator * $fraction -> denominator ); } } ?>
    10. ext/operator <?php require_once 'Fraction.php' ; $a = new Fraction ( 2 , 3 ); $b = new Fraction ( 4 , 2 ); print $a + $b ; ?> 16/6
    11. VLD (Vulcan Logic Disassembler)
      • Disassembler for PHP Bytecode
        • alias vld=&quot;php -dvld.active=1 -dvld.execute=0&quot;
      • Usefull for developers of
        • the Zend Engine
        • extensions for the Zend Engine such as
          • Debuggers
          • Optimizers
      • But also for “curious PHP developers”
    12. ext/parsekit
      • Provides read access to the op arrays that make up PHP's bytecode
      • API
        • parsekit_compile_string()
        • parsekit_compile_file()
      • Return value: multi-dimensional array
      • Usefull to (statically) analyze PHP code
    13. ext/parse_tree
      • Provides access to the parse tree of PHP source code
      • The tree
        • Is returned as an XML document that
        • can be transformed using XSLT, for instance and
        • can be transformed back to PHP source code
      • Usefull for
        • Analysis and Refactoring of PHP source code
        • Extending the syntax of PHP
          • Example: AspectPHP
    14. Interlude: AspectPHP
      • Aspect-Oriented Programming with PHP following the example of AspectJ for Java
      • Project in the Google Summer of Code 2006
        • ext/parse_tree is a by-product of this project
    15. Interlude: Aspect-Orientation
      • New modularization concept
        • Quantification
          • Execute code C when event E is triggered during the execution of program P
        • Obliviousness
          • Program P is oblivious to the code C , it does not provide hooks for the event E
      • Functionality that would otherwise be scattered across the codebase and tangled with other functionality can be cleanly abstracted and encapsulated
    16. Interlude: Aspect-Orientation New Object Join Point Method Call Join Point
    17. Interlude: AspectPHP <?php aspect Singleton { public $instances = array (); pointcut newObject : new( SomeClass ( * )); around newObject { $className = $thisJoinPoint -> getClassName (); if (! isset ( $thisAspect -> instances [ $className ])) { $thisAspect -> instances [ $className ] = proceed (); } return $thisAspect -> instances [ $className ]; } private function SomeClass :: __clone () {} } ?>
    18. Interlude: AspectPHP PHPAspect
    19. ext/runkit
      • Replace, rename, and delete classes, methods, and functions at runtime
      • Define additional super-global variables
      • Execute code in a sandbox
    20. ext/runkit <?php class Calculator {} $calculator = new Calculator ; runkit_method_add ( 'Calculator' , 'add' , '$a, $b' , 'return $a + $b;' , RUNKIT_ACC_PUBLIC ); print $calculator -> add ( 23 , 42 ); ?>
    21. Interlude: GAP
      • G eneric A spects for P HP
        • Generic Join Point Model for PHP
          • Framework for Pointcut Systems
        • Supports Aspect Genericity
      • An Advice is a “normal” PHP method
        • $joinPoint o bject inside this method
        • Default Pointcut System uses annotations to bind advice methods to join points
    22. Interlude: GAP <?php /* @pointcut allMethodCalls : method(* *->*(..)); * @after allMethodCalls : LoggingAspect->log(); */ class LoggingAspect { public function log ( $joinPoint ) { printf ( &quot;%s->%s() called %s->%s() &quot; , $joinPoint -> getSource ()-> getDeclaringClass () -> getName (), $joinPoint -> getSource ()-> getName (), $joinPoint -> getTarget ()-> getDeclaringClass () -> getName (), $joinPoint -> getTarget ()-> getName () ); } }
    23. ext/runkit weaveMethodJoinPoint ( ReflectionMethod $method ) { runkit_method_rename ( $method -> getDeclaringClass ()-> getName (), $method -> getName (), '__GAP_' . $method -> getName () ); runkit_method_add ( $method -> getDeclaringClass ()-> getName (), $method -> getName (), self :: generateMethodParameters ( $method ), 'return GAP_Dispatcher::getInstance() ->methodCall(new GAP_JoinPoint_Method);' ); }
    24. ext/intercept
      • Intercept function calls
      • Allows execution code before and after a function is executed
        • Allows for the implementation of AOP-style before- and around-advices, but not around
    25. ext/intercept <?php function foo () { print &quot;foo() &quot; ; } function before () { print &quot;before advice &quot; ; } function after () { print &quot;after advice &quot; ; } intercept_add ( 'foo' , 'before' , PRE_INTERCEPT ); intercept_add ( 'foo' , 'after' , POST_INTERCEPT ); foo ();
    26. The End
      • Thank you for your interest!
      • These slides will be available shortly on http://sebastian-bergmann.de/talks/.
    27. License
      • This presentation material is published under the Attribution-Share Alike 3.0 Unported license.
      • You are free:
          • to Share – to copy, distribute and transmit the work.
          • to Remix – to adapt the work.
      • Under the following conditions:
          • Attribution. You must attribute the work in the manner specified by the author or licensor (but not in any way that suggests that they endorse you or your use of the work).
          • Share Alike. If you alter, transform, or build upon this work, you may distribute the resulting work only under the same, similar or a compatible license.
      • For any reuse or distribution, you must make clear to others the license terms of this work.
      • Any of the above conditions can be waived if you get permission from the copyright holder.
      • Nothing in this license impairs or restricts the author's moral rights.

    + Sebastian BergmannSebastian Bergmann, 2 years ago

    custom

    1497 views, 2 favs, 2 embeds more stats

    A look into PECL shows how flexible the language co more

    More info about this document

    CC Attribution-ShareAlike LicenseCC Attribution-ShareAlike License

    Go to text version

    • Total Views 1497
      • 1427 on SlideShare
      • 70 from embeds
    • Comments 0
    • Favorites 2
    • Downloads 0
    Most viewed embeds
    • 68 views on http://sebastian-bergmann.de
    • 2 views on http://www.planet-php.net

    more

    All embeds
    • 68 views on http://sebastian-bergmann.de
    • 2 views on http://www.planet-php.net

    less

    Flagged as inappropriate Flag as inappropriate
    Flag as inappropriate

    Select your reason for flagging this presentation as inappropriate. If needed, use the feedback form to let us know more details.

    Cancel
    File a copyright complaint
    Having problems? Go to our helpdesk?

    Categories

    Tags