SlideShare uma empresa Scribd logo
1 de 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

Mais conteúdo relacionado

Mais procurados

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
 

Mais procurados (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)
 

Destaque

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
 

Destaque (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
 

Semelhante a 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
 

Semelhante a 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
 

Último

How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesBoston Institute of Analytics
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?Antenna Manufacturer Coco
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessPixlogix Infotech
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobeapidays
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAndrey Devyatkin
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024The Digital Insurer
 

Último (20)

How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 

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");