SlideShare ist ein Scribd-Unternehmen logo
1 von 67
flickr.com/photos: katkun/4349837202/By katkun
LOG.PHP:

       1. define("DEPOSIT",100);
       2. /**
       3. * getParams()
       4. * returns annual interest and how many hundreds
       5. **/
       6. function getParams() {
           7. $annual_interest = 0.05;
           8. $hundreds = 2;
           9. if ( isset( $_GET['ai'] ) ) {
            10.$annual_interest = (float) $_GET['ai'];
           11.}
           12.if (isset( $_GET['hu'] ) ) {
            13.$hundreds = (int) $_GET['hu'];
           14.}
           15.return array($annual_interest,$hundreds);
       16.}
       17.list ($annual_interest, $hundreds) = getParams();
       18.$percent_format = substr($annual_interest,-1,1) . '%';
       19.$rate = 1 + $annual_interest;
       20./** REMOVED:
       21.* $f = create_function('$x, $y', 'return round( log( $x ) / log( $y ),2 );' );
       22.*
       23.**/
       24.$f = function( $x, $y ) {
           25.return round( log( $x ) / log( $y ), 2 );
       26.};
       27.$x = $f( $hundreds, $rate );
THIS_AND_THAT.PHP:
      1. <?php
      2. class Example2 {
        3. private $secret_code = " <--{ -*- }--> ";
        4. function Square( $num ) {
         5. return $num * $num;
        6. }
        7. function getSecretSign()
        8. {
         9. return $this->secret_code;
        10.}
        11.function doIt( $x ) {
         12.$that = $this;
         13.return function ($y) use ($x, $that) {
             14.$special = $that->getSecretSign();
             15.return $special . ($that->Square( $x ) + $y) . $special;
         16.};
        17.}
      18.}
      19.$e2 = new Example2();
      20.$r = $e2->doIt( 10 );
      21.$rr = $r( 80 );
      22.include("this_and_that.template.php");
DIFFERENT_SCOPES.PHP:
      1. <?php
      2. include("lvd.header.php");
      3. ?>
      4. <script>
      5. var fact = function(n) {
        6. if( n <= 1 ){
         7. return 1;
        8. }
        9. else
        10.{
         11.return n * fact( n-1 );
        12.}
      13.};
      14.alert( fact( 4 ) );
      15.</script>
      16.<?php
      17.$fact = function( $n ){
        18.if( $n <= 1 ) {
         19.return 1;
         20.} else {
           21.return $n * $fact( $n-1 );
         22.}
        23.};
        24.$r = $fact( 4 ); // Output : Error
        25.include("lvd.footer.php");
DIFFERENT_SCOPES_GOOD.PHP:
      1. <?php include("lvd.header.php"); ?>
      2. <script>
      3. var fact = function( n ) {
        4. if( n <= 1 ){
         5. return 1;
         6. } else {
           7. return n * fact( n-1 );
         8. }
        9. };
        10.alert(fact(4))
        11.</script>
        12.<?php
        13.$fact = function( $n ) use( &$fact ) {
         14.if($n <= 1) {
           15.return 1;
         16.}
         17.else
         18.{
           19.return $n * $fact( $n-1 );
         20.}
        21.};
        22.$r = $fact( 4 );
        23.include("lvd.footer.php");
FERRARI.PHP:
       1. <?php
       2. // modified 1-24-2011
       3. // more info at
         http://www.ibm.com/developerworks/opensource/library/os-php-
         lambda/index.html?ca=drs-
       4. class Car {
        5. private $model;
        6. public $Drive;
        7. public function __construct( $model )
        8. {
          9. $this->model = $model;
        10.}
        11.public function __call( $method, $args ) {
          12.return call_user_func_array( $this->$method, $args );
        13.}
        14.public function __get($name) {
          15.return $this->$name;
        16.}
       17.}
       18.$car = new Car("Ferrari");
       19.$car->Drive = function( $speed ) use ( $car ) {
        20.return 'Varoom! ' . $car->model . ' is driving ' . $speed . ' mph and
              loving it.';
       21.};
       22.$r = array();
       23.$r[0] = $car->Drive("90");
       24.$go_for_it = $car->Drive;
       25.unset( $car );
       26.$r[1] = $go_for_it("120");
       27.include("ferrari.template.php");
INVOKE_EXAMPLE.PHP:

      1. <?php
      2. class Determinator {
       3. public $x;
       4. public function __construct( $x ) {
         5. $this->x = (int) $x;
       6. }
       7. public function __invoke() {
         8. $res = ($this->x % 2 == 1)? ' odd': 'even';
         9. return " // $d->x is $res <span style='font: 70% Arial,Helvetica'>
              ( " . $this->x . " )</span>";
       10.}
      11.}
      12.$num = pow(3,4) - 5;
      13.$d = new Determinator( $num );
      14.$r[] = $d();
      15.$d->x = pow(4,3) - 7;
      16.$r[] = $d->__invoke() . '<br>';
      17.include("invoke_example.template.php");
FERRARI2.PHP:
       1. <?php
       2. // modified 1-24-2011
       3. class Car {
        4. private $model;
        5. public function __construct( $model )
        6. {
          7. $this->model = $model;
        8. }
        9. public function __get($name) {
          10.return $this->$name;
        11.}
        12.public function Action( Closure $act, $speed=null ) {
          13.return $act($speed);
        14.}
       15.}
       16.$car = new Car("Ferrari");
       17.$closure = function( $speed ) use ( $car ) {
        18.return 'Varoom! ' . $car->model . ' is driving ' . $speed . ' mph and
              loving it.';
       19.};
       20.$lambda = function() {
        21.return "<strong>Hellow, World!</strong>";
       22.};
       23.$r = array();
       24.$r[0] = $car->Action( $lambda );
       25.$r[1] = $car->Action( $closure, "135");
       26.include("ferrari.template2.php");
The Truth About Lambdas in PHP
The Truth About Lambdas in PHP
The Truth About Lambdas in PHP
The Truth About Lambdas in PHP
The Truth About Lambdas in PHP

Weitere ähnliche Inhalte

Was ist angesagt?

basic shell_programs
 basic shell_programs basic shell_programs
basic shell_programsmadhugvskr
 
Pim Elshoff "Final Class Aggregate"
Pim Elshoff "Final Class Aggregate"Pim Elshoff "Final Class Aggregate"
Pim Elshoff "Final Class Aggregate"Fwdays
 
Et si on en finissait avec CRUD ?
Et si on en finissait avec CRUD ?Et si on en finissait avec CRUD ?
Et si on en finissait avec CRUD ?Julien Vinber
 
Five things for you - Yahoo developer offers
Five things for you - Yahoo developer offersFive things for you - Yahoo developer offers
Five things for you - Yahoo developer offersChristian Heilmann
 
Les exceptions, oui, mais pas n'importe comment
Les exceptions, oui, mais pas n'importe commentLes exceptions, oui, mais pas n'importe comment
Les exceptions, oui, mais pas n'importe commentCharles Desneuf
 
Desymfony2013.gonzalo123
Desymfony2013.gonzalo123Desymfony2013.gonzalo123
Desymfony2013.gonzalo123Gonzalo Ayuso
 
循環参照のはなし
循環参照のはなし循環参照のはなし
循環参照のはなしMasahiro Honma
 
Twib in Yokoahma.pm 2010/3/5
Twib in Yokoahma.pm 2010/3/5Twib in Yokoahma.pm 2010/3/5
Twib in Yokoahma.pm 2010/3/5Yusuke Wada
 
Build your own RESTful API with Laravel
Build your own RESTful API with LaravelBuild your own RESTful API with Laravel
Build your own RESTful API with LaravelFrancisco Carvalho
 
Introduction to CloudForecast / YAPC::Asia 2010 Tokyo
Introduction to CloudForecast / YAPC::Asia 2010 TokyoIntroduction to CloudForecast / YAPC::Asia 2010 Tokyo
Introduction to CloudForecast / YAPC::Asia 2010 TokyoMasahiro Nagano
 
Decoupling Objects With Standard Interfaces
Decoupling Objects With Standard InterfacesDecoupling Objects With Standard Interfaces
Decoupling Objects With Standard InterfacesThomas Weinert
 
エロサイト管理者の憂鬱3 - Hokkaiodo.pm#4 -
エロサイト管理者の憂鬱3 - Hokkaiodo.pm#4 -エロサイト管理者の憂鬱3 - Hokkaiodo.pm#4 -
エロサイト管理者の憂鬱3 - Hokkaiodo.pm#4 -Yusuke Wada
 
Coding Horrors
Coding HorrorsCoding Horrors
Coding HorrorsMark Baker
 
Security Meetup 22 октября. «Реверс-инжиниринг в Enterprise». Алексей Секрето...
Security Meetup 22 октября. «Реверс-инжиниринг в Enterprise». Алексей Секрето...Security Meetup 22 октября. «Реверс-инжиниринг в Enterprise». Алексей Секрето...
Security Meetup 22 октября. «Реверс-инжиниринг в Enterprise». Алексей Секрето...Mail.ru Group
 
Fat Arrow (ES6)
Fat Arrow (ES6)Fat Arrow (ES6)
Fat Arrow (ES6)Ryan Ewing
 

Was ist angesagt? (20)

basic shell_programs
 basic shell_programs basic shell_programs
basic shell_programs
 
Pim Elshoff "Final Class Aggregate"
Pim Elshoff "Final Class Aggregate"Pim Elshoff "Final Class Aggregate"
Pim Elshoff "Final Class Aggregate"
 
画像Hacks
画像Hacks画像Hacks
画像Hacks
 
Et si on en finissait avec CRUD ?
Et si on en finissait avec CRUD ?Et si on en finissait avec CRUD ?
Et si on en finissait avec CRUD ?
 
Feeds drupal cafe
Feeds drupal cafeFeeds drupal cafe
Feeds drupal cafe
 
Five things for you - Yahoo developer offers
Five things for you - Yahoo developer offersFive things for you - Yahoo developer offers
Five things for you - Yahoo developer offers
 
Les exceptions, oui, mais pas n'importe comment
Les exceptions, oui, mais pas n'importe commentLes exceptions, oui, mais pas n'importe comment
Les exceptions, oui, mais pas n'importe comment
 
Desymfony2013.gonzalo123
Desymfony2013.gonzalo123Desymfony2013.gonzalo123
Desymfony2013.gonzalo123
 
循環参照のはなし
循環参照のはなし循環参照のはなし
循環参照のはなし
 
Twib in Yokoahma.pm 2010/3/5
Twib in Yokoahma.pm 2010/3/5Twib in Yokoahma.pm 2010/3/5
Twib in Yokoahma.pm 2010/3/5
 
Build your own RESTful API with Laravel
Build your own RESTful API with LaravelBuild your own RESTful API with Laravel
Build your own RESTful API with Laravel
 
Introduction to CloudForecast / YAPC::Asia 2010 Tokyo
Introduction to CloudForecast / YAPC::Asia 2010 TokyoIntroduction to CloudForecast / YAPC::Asia 2010 Tokyo
Introduction to CloudForecast / YAPC::Asia 2010 Tokyo
 
Decoupling Objects With Standard Interfaces
Decoupling Objects With Standard InterfacesDecoupling Objects With Standard Interfaces
Decoupling Objects With Standard Interfaces
 
エロサイト管理者の憂鬱3 - Hokkaiodo.pm#4 -
エロサイト管理者の憂鬱3 - Hokkaiodo.pm#4 -エロサイト管理者の憂鬱3 - Hokkaiodo.pm#4 -
エロサイト管理者の憂鬱3 - Hokkaiodo.pm#4 -
 
Coding Horrors
Coding HorrorsCoding Horrors
Coding Horrors
 
week-2x
week-2xweek-2x
week-2x
 
Clean code in unit testing
Clean code in unit testingClean code in unit testing
Clean code in unit testing
 
Blog Hacks 2011
Blog Hacks 2011Blog Hacks 2011
Blog Hacks 2011
 
Security Meetup 22 октября. «Реверс-инжиниринг в Enterprise». Алексей Секрето...
Security Meetup 22 октября. «Реверс-инжиниринг в Enterprise». Алексей Секрето...Security Meetup 22 октября. «Реверс-инжиниринг в Enterprise». Алексей Секрето...
Security Meetup 22 октября. «Реверс-инжиниринг в Enterprise». Алексей Секрето...
 
Fat Arrow (ES6)
Fat Arrow (ES6)Fat Arrow (ES6)
Fat Arrow (ES6)
 

Andere mochten auch

Promocione su empresa_en_la_web
Promocione su empresa_en_la_webPromocione su empresa_en_la_web
Promocione su empresa_en_la_webOscar Valbuena
 
Make Web, Not War - Open Source Microsoft Event
Make Web, Not War - Open Source Microsoft EventMake Web, Not War - Open Source Microsoft Event
Make Web, Not War - Open Source Microsoft EventBrendan Sera-Shriar
 
The Zen of Lithium
The Zen of LithiumThe Zen of Lithium
The Zen of LithiumNate Abele
 
Introducing Assetic: Asset Management for PHP 5.3
Introducing Assetic: Asset Management for PHP 5.3Introducing Assetic: Asset Management for PHP 5.3
Introducing Assetic: Asset Management for PHP 5.3Kris Wallsmith
 
New Features in PHP 5.3
New Features in PHP 5.3New Features in PHP 5.3
New Features in PHP 5.3Bradley Holt
 

Andere mochten auch (10)

Create our own keylogger
Create our own keyloggerCreate our own keylogger
Create our own keylogger
 
Promocione su empresa_en_la_web
Promocione su empresa_en_la_webPromocione su empresa_en_la_web
Promocione su empresa_en_la_web
 
Lesson three
Lesson threeLesson three
Lesson three
 
Make Web, Not War - Open Source Microsoft Event
Make Web, Not War - Open Source Microsoft EventMake Web, Not War - Open Source Microsoft Event
Make Web, Not War - Open Source Microsoft Event
 
PHP Reset
PHP ResetPHP Reset
PHP Reset
 
あらためてPHP5.3
あらためてPHP5.3あらためてPHP5.3
あらためてPHP5.3
 
The Zen of Lithium
The Zen of LithiumThe Zen of Lithium
The Zen of Lithium
 
Introduction to Imagine
Introduction to ImagineIntroduction to Imagine
Introduction to Imagine
 
Introducing Assetic: Asset Management for PHP 5.3
Introducing Assetic: Asset Management for PHP 5.3Introducing Assetic: Asset Management for PHP 5.3
Introducing Assetic: Asset Management for PHP 5.3
 
New Features in PHP 5.3
New Features in PHP 5.3New Features in PHP 5.3
New Features in PHP 5.3
 

Ähnlich wie The Truth About Lambdas in PHP

PHPCon 2016: PHP7 by Witek Adamus / XSolve
PHPCon 2016: PHP7 by Witek Adamus / XSolvePHPCon 2016: PHP7 by Witek Adamus / XSolve
PHPCon 2016: PHP7 by Witek Adamus / XSolveXSolve
 
Melhorando sua API com DSLs
Melhorando sua API com DSLsMelhorando sua API com DSLs
Melhorando sua API com DSLsAugusto Pascutti
 
PHP Experience 2016 - [Palestra] Melhorando a comunicação da API através de DSL
PHP Experience 2016 - [Palestra] Melhorando a comunicação da API através de DSLPHP Experience 2016 - [Palestra] Melhorando a comunicação da API através de DSL
PHP Experience 2016 - [Palestra] Melhorando a comunicação da API através de DSLiMasters
 
How Kris Writes Symfony Apps
How Kris Writes Symfony AppsHow Kris Writes Symfony Apps
How Kris Writes Symfony AppsKris Wallsmith
 
Adding Dependency Injection to Legacy Applications
Adding Dependency Injection to Legacy ApplicationsAdding Dependency Injection to Legacy Applications
Adding Dependency Injection to Legacy ApplicationsSam Hennessy
 
Rich domain model with symfony 2.5 and doctrine 2.5
Rich domain model with symfony 2.5 and doctrine 2.5Rich domain model with symfony 2.5 and doctrine 2.5
Rich domain model with symfony 2.5 and doctrine 2.5Leonardo Proietti
 
Redis & ZeroMQ: How to scale your application
Redis & ZeroMQ: How to scale your applicationRedis & ZeroMQ: How to scale your application
Redis & ZeroMQ: How to scale your applicationrjsmelo
 
エラー時にログに出力する情報と画面に表示する情報を分ける #LaravelTokyo
エラー時にログに出力する情報と画面に表示する情報を分ける #LaravelTokyoエラー時にログに出力する情報と画面に表示する情報を分ける #LaravelTokyo
エラー時にログに出力する情報と画面に表示する情報を分ける #LaravelTokyoShohei Okada
 
Doctrine For Beginners
Doctrine For BeginnersDoctrine For Beginners
Doctrine For BeginnersJonathan Wage
 
Design Patterns avec PHP 5.3, Symfony et Pimple
Design Patterns avec PHP 5.3, Symfony et PimpleDesign Patterns avec PHP 5.3, Symfony et Pimple
Design Patterns avec PHP 5.3, Symfony et PimpleHugo Hamon
 
jQuery: out with the old, in with the new
jQuery: out with the old, in with the newjQuery: out with the old, in with the new
jQuery: out with the old, in with the newRemy Sharp
 
Silex meets SOAP & REST
Silex meets SOAP & RESTSilex meets SOAP & REST
Silex meets SOAP & RESTHugo Hamon
 
Tidy Up Your Code
Tidy Up Your CodeTidy Up Your Code
Tidy Up Your CodeAbbas Ali
 
Introduction to Zend Framework web services
Introduction to Zend Framework web servicesIntroduction to Zend Framework web services
Introduction to Zend Framework web servicesMichelangelo van Dam
 
ZF2 for the ZF1 Developer
ZF2 for the ZF1 DeveloperZF2 for the ZF1 Developer
ZF2 for the ZF1 DeveloperGary Hockin
 

Ähnlich wie The Truth About Lambdas in PHP (20)

Functional php
Functional phpFunctional php
Functional php
 
PHPCon 2016: PHP7 by Witek Adamus / XSolve
PHPCon 2016: PHP7 by Witek Adamus / XSolvePHPCon 2016: PHP7 by Witek Adamus / XSolve
PHPCon 2016: PHP7 by Witek Adamus / XSolve
 
Design Patterns
Design PatternsDesign Patterns
Design Patterns
 
Melhorando sua API com DSLs
Melhorando sua API com DSLsMelhorando sua API com DSLs
Melhorando sua API com DSLs
 
PHP Experience 2016 - [Palestra] Melhorando a comunicação da API através de DSL
PHP Experience 2016 - [Palestra] Melhorando a comunicação da API através de DSLPHP Experience 2016 - [Palestra] Melhorando a comunicação da API através de DSL
PHP Experience 2016 - [Palestra] Melhorando a comunicação da API através de DSL
 
How Kris Writes Symfony Apps
How Kris Writes Symfony AppsHow Kris Writes Symfony Apps
How Kris Writes Symfony Apps
 
Adding Dependency Injection to Legacy Applications
Adding Dependency Injection to Legacy ApplicationsAdding Dependency Injection to Legacy Applications
Adding Dependency Injection to Legacy Applications
 
Rich domain model with symfony 2.5 and doctrine 2.5
Rich domain model with symfony 2.5 and doctrine 2.5Rich domain model with symfony 2.5 and doctrine 2.5
Rich domain model with symfony 2.5 and doctrine 2.5
 
Redis & ZeroMQ: How to scale your application
Redis & ZeroMQ: How to scale your applicationRedis & ZeroMQ: How to scale your application
Redis & ZeroMQ: How to scale your application
 
エラー時にログに出力する情報と画面に表示する情報を分ける #LaravelTokyo
エラー時にログに出力する情報と画面に表示する情報を分ける #LaravelTokyoエラー時にログに出力する情報と画面に表示する情報を分ける #LaravelTokyo
エラー時にログに出力する情報と画面に表示する情報を分ける #LaravelTokyo
 
Unittests für Dummies
Unittests für DummiesUnittests für Dummies
Unittests für Dummies
 
Symfony tips and tricks
Symfony tips and tricksSymfony tips and tricks
Symfony tips and tricks
 
Doctrine For Beginners
Doctrine For BeginnersDoctrine For Beginners
Doctrine For Beginners
 
Bacbkone js
Bacbkone jsBacbkone js
Bacbkone js
 
Design Patterns avec PHP 5.3, Symfony et Pimple
Design Patterns avec PHP 5.3, Symfony et PimpleDesign Patterns avec PHP 5.3, Symfony et Pimple
Design Patterns avec PHP 5.3, Symfony et Pimple
 
jQuery: out with the old, in with the new
jQuery: out with the old, in with the newjQuery: out with the old, in with the new
jQuery: out with the old, in with the new
 
Silex meets SOAP & REST
Silex meets SOAP & RESTSilex meets SOAP & REST
Silex meets SOAP & REST
 
Tidy Up Your Code
Tidy Up Your CodeTidy Up Your Code
Tidy Up Your Code
 
Introduction to Zend Framework web services
Introduction to Zend Framework web servicesIntroduction to Zend Framework web services
Introduction to Zend Framework web services
 
ZF2 for the ZF1 Developer
ZF2 for the ZF1 DeveloperZF2 for the ZF1 Developer
ZF2 for the ZF1 Developer
 

Kürzlich hochgeladen

Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusZilliz
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Jeffrey Haguewood
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businesspanagenda
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...apidays
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Victor Rentea
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfOrbitshub
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfOverkill Security
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...apidays
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdfSandro Moreira
 
Cyberprint. Dark Pink Apt Group [EN].pdf
Cyberprint. Dark Pink Apt Group [EN].pdfCyberprint. Dark Pink Apt Group [EN].pdf
Cyberprint. Dark Pink Apt Group [EN].pdfOverkill Security
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...apidays
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MIND CTI
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century educationjfdjdjcjdnsjd
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Orbitshub
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWERMadyBayot
 
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUKSpring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUKJago de Vreede
 

Kürzlich hochgeladen (20)

Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdf
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
Cyberprint. Dark Pink Apt Group [EN].pdf
Cyberprint. Dark Pink Apt Group [EN].pdfCyberprint. Dark Pink Apt Group [EN].pdf
Cyberprint. Dark Pink Apt Group [EN].pdf
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUKSpring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
 

The Truth About Lambdas in PHP

  • 1.
  • 2.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18. LOG.PHP: 1. define("DEPOSIT",100); 2. /** 3. * getParams() 4. * returns annual interest and how many hundreds 5. **/ 6. function getParams() { 7. $annual_interest = 0.05; 8. $hundreds = 2; 9. if ( isset( $_GET['ai'] ) ) { 10.$annual_interest = (float) $_GET['ai']; 11.} 12.if (isset( $_GET['hu'] ) ) { 13.$hundreds = (int) $_GET['hu']; 14.} 15.return array($annual_interest,$hundreds); 16.} 17.list ($annual_interest, $hundreds) = getParams(); 18.$percent_format = substr($annual_interest,-1,1) . '%'; 19.$rate = 1 + $annual_interest; 20./** REMOVED: 21.* $f = create_function('$x, $y', 'return round( log( $x ) / log( $y ),2 );' ); 22.* 23.**/ 24.$f = function( $x, $y ) { 25.return round( log( $x ) / log( $y ), 2 ); 26.}; 27.$x = $f( $hundreds, $rate );
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.
  • 34.
  • 35.
  • 36.
  • 37.
  • 38.
  • 39.
  • 40.
  • 41.
  • 42.
  • 43.
  • 44.
  • 45. THIS_AND_THAT.PHP: 1. <?php 2. class Example2 { 3. private $secret_code = " <--{ -*- }--> "; 4. function Square( $num ) { 5. return $num * $num; 6. } 7. function getSecretSign() 8. { 9. return $this->secret_code; 10.} 11.function doIt( $x ) { 12.$that = $this; 13.return function ($y) use ($x, $that) { 14.$special = $that->getSecretSign(); 15.return $special . ($that->Square( $x ) + $y) . $special; 16.}; 17.} 18.} 19.$e2 = new Example2(); 20.$r = $e2->doIt( 10 ); 21.$rr = $r( 80 ); 22.include("this_and_that.template.php");
  • 46.
  • 47.
  • 48.
  • 49. DIFFERENT_SCOPES.PHP: 1. <?php 2. include("lvd.header.php"); 3. ?> 4. <script> 5. var fact = function(n) { 6. if( n <= 1 ){ 7. return 1; 8. } 9. else 10.{ 11.return n * fact( n-1 ); 12.} 13.}; 14.alert( fact( 4 ) ); 15.</script> 16.<?php 17.$fact = function( $n ){ 18.if( $n <= 1 ) { 19.return 1; 20.} else { 21.return $n * $fact( $n-1 ); 22.} 23.}; 24.$r = $fact( 4 ); // Output : Error 25.include("lvd.footer.php");
  • 50.
  • 51. DIFFERENT_SCOPES_GOOD.PHP: 1. <?php include("lvd.header.php"); ?> 2. <script> 3. var fact = function( n ) { 4. if( n <= 1 ){ 5. return 1; 6. } else { 7. return n * fact( n-1 ); 8. } 9. }; 10.alert(fact(4)) 11.</script> 12.<?php 13.$fact = function( $n ) use( &$fact ) { 14.if($n <= 1) { 15.return 1; 16.} 17.else 18.{ 19.return $n * $fact( $n-1 ); 20.} 21.}; 22.$r = $fact( 4 ); 23.include("lvd.footer.php");
  • 52.
  • 53. FERRARI.PHP: 1. <?php 2. // modified 1-24-2011 3. // more info at http://www.ibm.com/developerworks/opensource/library/os-php- lambda/index.html?ca=drs- 4. class Car { 5. private $model; 6. public $Drive; 7. public function __construct( $model ) 8. { 9. $this->model = $model; 10.} 11.public function __call( $method, $args ) { 12.return call_user_func_array( $this->$method, $args ); 13.} 14.public function __get($name) { 15.return $this->$name; 16.} 17.} 18.$car = new Car("Ferrari"); 19.$car->Drive = function( $speed ) use ( $car ) { 20.return 'Varoom! ' . $car->model . ' is driving ' . $speed . ' mph and loving it.'; 21.}; 22.$r = array(); 23.$r[0] = $car->Drive("90"); 24.$go_for_it = $car->Drive; 25.unset( $car ); 26.$r[1] = $go_for_it("120"); 27.include("ferrari.template.php");
  • 54.
  • 55.
  • 56.
  • 57.
  • 58.
  • 59.
  • 60. INVOKE_EXAMPLE.PHP: 1. <?php 2. class Determinator { 3. public $x; 4. public function __construct( $x ) { 5. $this->x = (int) $x; 6. } 7. public function __invoke() { 8. $res = ($this->x % 2 == 1)? ' odd': 'even'; 9. return " // $d->x is $res <span style='font: 70% Arial,Helvetica'> ( " . $this->x . " )</span>"; 10.} 11.} 12.$num = pow(3,4) - 5; 13.$d = new Determinator( $num ); 14.$r[] = $d(); 15.$d->x = pow(4,3) - 7; 16.$r[] = $d->__invoke() . '<br>'; 17.include("invoke_example.template.php");
  • 61.
  • 62. FERRARI2.PHP: 1. <?php 2. // modified 1-24-2011 3. class Car { 4. private $model; 5. public function __construct( $model ) 6. { 7. $this->model = $model; 8. } 9. public function __get($name) { 10.return $this->$name; 11.} 12.public function Action( Closure $act, $speed=null ) { 13.return $act($speed); 14.} 15.} 16.$car = new Car("Ferrari"); 17.$closure = function( $speed ) use ( $car ) { 18.return 'Varoom! ' . $car->model . ' is driving ' . $speed . ' mph and loving it.'; 19.}; 20.$lambda = function() { 21.return "<strong>Hellow, World!</strong>"; 22.}; 23.$r = array(); 24.$r[0] = $car->Action( $lambda ); 25.$r[1] = $car->Action( $closure, "135"); 26.include("ferrari.template2.php");