Lambda Functions | Closures | Functors

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.

1 comments

Comments 1 - 1 of 1 previous next Post a comment

  • + drx777 drx777 10 months ago
    As if I was there.

    Danke für die prägnante Präsentation.
Post a comment
Embed Video
Edit your comment Cancel

1 Favorite

Lambda Functions | Closures | Functors - Presentation Transcript

  1. Lambda Functions | Closures | Functors Sebastian Bergmann 9. Januar 2009
  2. Neue Sprachmerkmale in PHP PHP 5.3  Lambda Functions  Closures  Functors  Namespaces  Zukunft  Traits 
  3. Lambda Functions Anonyme Funktionen, die  an der Stelle ihrer Verwendung deklariert  werden, einer Variablen zugewiesen und  anderen Funktionen als Argument übergeben  werden können
  4. Lambda Functions Verwendung <?php $lambda = function() { print 'Hello World!'; }; ?>
  5. Lambda Functions Verwendung <?php $lambda = function() { print 'Hello World!'; }; $lambda(); ?> Hello World!
  6. Lambda Functions Verwendung <?php $lambda = function() { print 'Hello World!'; }; call_user_func($lambda); ?> Hello World!
  7. Lambda Functions Verwendung <?php $lambda = function() { print 'Hello World!'; }; call_user_func_array($lambda, array()); ?> Hello World!
  8. Lambda Functions Einsatzgebiete <?php $list = array(22, 4, 19, 78); usort( $list, function ($a, $b) { if ($a == $b) return 0; return ($a < $b) ? -1 : 1; } ); print_r($list); ?> Array ( [0] => 4 [1] => 19 [2] => 22 [3] => 78 )
  9. Lambda Functions Einsatzgebiete <?php print_r( array_map( function ($n) { return($n * $n * $n); }, array(1, 2, 3, 4, 5) ) ); ?> Array ( [0] => 1 [1] => 8 [2] => 27 [3] => 64 [4] => 125 )
  10. Lambda Functions Vor PHP 5.3 <?php $lambda = create_function('', 'print \"Hello World!\";'); $lambda(); ?> Hello World!
  11. Lambda Functions Vor PHP 5.3 <?php $lambda = create_function('', 'print \"Hello World!\";'); call_user_func($lambda); ?> Hello World!
  12. Lambda Functions Vor PHP 5.3 <?php $lambda = create_function('', 'print \"Hello World!\";'); call_user_func_array($lambda, array()); ?> Hello World!
  13. Closures Anonyme Funktionen, die  an der Stelle ihrer Verwendung deklariert  werden, einer Variablen zugewiesen,  anderen Funktionen als Argument  übergeben werden können und Zugriff auf den sie aufrufenden Scope haben 
  14. Closures Lexikalische Variablen <?php $string = 'Hello World!'; $closure = function() use ($string) { print $string; }; $closure(); ?> Hello World!
  15. Closures Lexikalische Variablen mit Referenz <?php $x = 1; $closure = function() use (&$x) { $x++; }; $closure(); print $x; ?> 2
  16. Closures $this als lexikalische Variable <?php class Example { public function one() { print __METHOD__ . \"\\n\"; $closure = function() { $this->two(); }; $closure(); } public function two() { print __METHOD__ . \"\\n\"; } } $object = new Example; $object->one(); ?> Example::one Example::two
  17. Closures Reflection API <?php $closure = function($a, $b) { return $a + $b; }; $reflector = new ReflectionFunction($closure); print $reflector; ?> Closure [ <user> function {closure} ] { @@ /home/sb/closure_reflection.php 2 - 2 - Parameters [2] { Parameter #0 [ <required> $a ] Parameter #1 [ <required> $b ] } }
  18. Functors Ermöglichen es, ein Objekt ”aufzurufen” als  wäre es eine gewöhnliche Funktion Auch function objects, functionals oder  functionoids genannt
  19. Functors Verwendung <?php class Functor { public function __invoke() { print __METHOD__ . \"\\n\"; } } $functor = new Functor; $functor(); ?> Functor::__invoke
  20. The End Thank you for your interest! These slides will be linked soon from http://sebastian-bergmann.de/
  21. 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, 10 months ago

custom

1786 views, 1 favs, 0 embeds more stats

Presentation on new language features in PHP 5.3 at more

More info about this document

© All Rights Reserved

Go to text version

  • Total Views 1786
    • 1786 on SlideShare
    • 0 from embeds
  • Comments 1
  • Favorites 1
  • Downloads 11
Most viewed embeds

more

All embeds

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