SlideShare ist ein Scribd-Unternehmen logo
1 von 38
Downloaden Sie, um offline zu lesen
PHP 5.3 OVERVIEW
   6/8/2010 - Dallas PHP
         Jake Smith
PERFORMANCE
• Over   140 bug fixes

• 40%+   improvement with PHP on Windows

• 5%   - 15% overall performance improvement

 • MD5     roughly 15% faster

 • Constants   move to read-only memory

• Drupal   20% faster, Wordpress 15% faster
ADDITIONS

• New   error_reporting E_DEPRECATED

• Garbage   collection

• MySQLnd    (Native Driver)

 • No   longer uses libmysql

 • No   PDO support (currently)

 • MySQL     version 4.1+
BACKWARDS COMPATIBILITY

• EREG        Family is now E_DEPRECATED

  • Use       the Pearl Compatible (PCRE)

• __toString          does not accept arguments/parameters

• Magic      methods must be public and can not be static

• __call     is now invoked on access to private/protected methods

• Classes       can not be named Namespace or Closure
  SOURCES: http://us2.php.net/manual/en/migration53.incompatible.php
MAGIC METHODS IN 5.3
<?php

class Backwards {

    public function __call($method, $value) {
        echo "Call Magic Method<br />n";
    }

    private function __get($method) {

    }

    private function __set($method, $value) {

    }

    private function getElements() {
        echo "Get Elements<br />n";
    }
}

$bc = new Backwards();

$bc->getElements();
CHANGES IN PHP.INI

• INI Variables

• Per   Folder/Per Site ini settings

• User   specified ini files
.INI VARIABLES
error_dev = E_ALL
error_prod = E_NONE

[HOST=dev.mydomain.com]
error_reporting = ${error_dev}

[HOST=mydomain.com]
error_reporting = ${error_prod}

[PATH=/var/www/vhosts/myotherdomain.com]
error_reporting = ${error_prod}

# User Defined ini. Place in web root. Set to blank to disable
user_ini.filename = .user.ini

user_ini.cache_ttl = 300
SLOW ADOPTION

• Open    Source projects were initially not compatible with PHP
 5.3

• Currentlymost major Open Source software (Wordpress,
 Drupal, Joomla and Magento) work in PHP 5.3

• Key   plugins are lacking behind
PECL ADDITIONS

• PECL Added

 • FileInfo, Intl, Phar, MySQLnd, SQLite3

• PECL      Removed

 • ncurses, FPDF, dbase, fbsql, ming




 SOURCES: http://php.net/releases/5_3_0.php
SPL ADDITIONS

• GlobIterator           - Iterator utilizing glob, look up glob function

• SplFixedArray             - Fixed size/dimension array

• SplQueue

• SplHeap

• SplStack

 SOURCES: http://matthewturland.com/2010/05/20/new-spl-features-in-php-5-3/
NEW CONSTANTS

• __DIR__

 • No   more dirname(__FILE__);

• __NAMESPACE__

 • Current   namespace
NEW OPERATORS

• Ternary   Operator ?:

• Goto

• NOWDOC
TERNARY OPERATOR
<?php
// Before PHP 5.3
$action = $_POST['action'] ? $_POST['action'] : 'Default Action';

// Now in PHP 5.3 (less time)
$action = $_POST['action'] ?: 'Default Action';
GOTO




SOURCES: http://xkcd.com/292/
GOTO EXAMPLE
                           <?php
                           for($i=0,$j=50; $i<100; $i++) {
                             while($j--) {
                               if($j==17) goto end;
                             }
                           }

                           echo "i = $i";

                           end: // End
                           echo 'j hit 17';




SOURCES: http://php.net/manual/en/control-structures.goto.php
NOWDOC VS. HEREDOC

• NOWDOC    works just like HEREDOC, except it does not
evaluate PHP variables

      <?php
      $myVar = 'testing';
      // OUTPUT: Here is my text testing
      $longString = <<<HEREDOC
      Here is my text $myVar
      HEREDOC;

      // OUTPUT: Here is my text $myVar
      $longString = <<<'NOWDOC'
      Here is my text $myVar
      'NOWDOC';
DATE/TIME OBJECT
                      ADDITIONS
• New      functions/methods added to Date/Time Object

 • date_add, date_sub                     and date_diff
           <?php
           $date = new DateTime('2000-01-01');
           $date->add(new DateInterval('P10D'));
           echo $date->format('Y-m-d') . "n";

           // OR

           $date = date_create('200-01-01');
           date_add($date, date_interval_create_from_date_string('10 days'));
           echo date_format($date, 'Y-m-d');


 SOURCES: http://www.php.net/manual/en/class.datetime.php
NEW METHODS

• Functors/__invoke

• Dynamic   Static Method

• __callStatic

• get_called_class()
__INVOKE
<?php
class Functor {

    public function __invoke($param = null)
    {
        return 'Hello Param: ' . $param;
    }
}

$func = new Functor();
echo $func('PHP 5.3'); // Hello Param: PHP 5.3
DYNAMIC STATIC METHOD
   <?php
   abstract class Model
   {
       const TABLE_NAME = '';

       public static function __call($method, $params)
       {
           // Run logic
           return $this->$method($criteria, $order, $limit, $offset);
       }
   }
DYNAMIC STATIC METHOD
  <?php
  abstract class Model
  {
      const TABLE_NAME = '';

      public static function __callStatic($method, $params)
      {
          // Run logic
          return static::$method($criteria, $order, $limit, $offset);
      }
  }
__CALLSTATIC

• __callStatic   works exactly like __call, except it’s a static
 method

  • Acts   as a catch all for all undefined methods (get or set)
            <?php
            abstract class Model
            {
                const TABLE_NAME = '';

                 public static function __callStatic($method, $params)
                 {
                     // Run logic
                     return static::$method($criteria, $order, $limit, $offset);
                 }
            }
GET_CLASS_CALLED

• get_called_class   returns the class name that called on the
 parent method
GET_CLASS_CALLED
<?php
    namespace App {
        abstract class Model {
            public static function __callStatic($method, $params)
            {
                // Search Logic
                $method = $matches[1];
                return static::$method($criteria, $order, $limit, $offset);
            }

             public static function find($criteria = array(), $order = null, $limit = null, $offset = 0)
             {
                 $tableName = strtolower(get_class_called()); // get_class_called will return Post
             }
         }
     }
     namespace AppModels {
         class Post extends AppModel {}
     }

     // Returns all the posts that contain Dallas PHP in the title
     $posts = Post::findByTitle('Dallas PHP');
?>
LATE STATIC BINDING

• This feature was named "late static bindings" with an internal
 perspective in mind. "Late binding" comes from the fact that
 static:: will no longer be resolved using the class where the
 method is defined but it will rather be computed using
 runtime information.




 SOURCES: http://us.php.net/lsb
LSB BEFORE PHP 5.3
<?php

class Model {
    const TABLE_NAME = '';

    public static function getTable()
    {
        return self::TABLE_NAME;
    }
}

class Author extends Model {
    const TABLE_NAME = 'Author';
}

class Post extends Model {
    const TABLE_NAME = 'Post'
}

// sadly you get nothing
echo Post::TABLE_NAME;
LSB PHP 5.3.X

• static   keyword to save the day!
                <?php

                class Model {
                    const TABLE_NAME = '';

                    public static function getTable()
                    {
                        return static::TABLE_NAME;
                    }
                }

                class Author extends Model {
                    const TABLE_NAME = 'Author';
                }

                class Post extends Model {
                    const TABLE_NAME = 'Post'
                }

                // sadly you get nothing
                echo Post::TABLE_NAME;
LAMBDA IN PHP 5.3

• Anonymous    functions, also known as closures, allow the
 creation of functions which have no specified name. They are
 most useful as the value of callback parameters, but they have
 many other uses.

• Good   function examples: array_map() and array_walk()

          <?php
          $string = 'Testing';
          $array = array('hello', 'world', 'trying', 'PHP 5.3');
          $return = array_walk($array, function($v,$k) {
              echo ucwords($v);
          });
LAMBDA EXAMPLE (JQUERY)


     $('.button').click(function() {
         $(this).hide();
     });
CLOSURE
<?php
// Cycle factory: takes a series of arguments
// for the closure to cycle over.
function getRowColor (array $colors) {
    $i = 0;
    $max = count($colors);
    $colors = array_values($colors);
    $color = function() use (&$i, $max, $colors) {
        $color = $colors[$i];
        $i = ($i + 1) % $max;
        return $color;
    };
    return $color;
}

$rowColor = getRowColor(array('#FFF', '#F00', '#000'));
echo $rowColor() . '<br />';
echo $rowColor() . '<br />';
echo $rowColor() . '<br />';
echo $rowColor() . '<br />';
echo $rowColor() . '<br />';
echo $rowColor() . '<br />';
NAMESPACES

• Before   PHP 5.3

 • PHP didn’t have namespaces, so we created a standard:
   “Zend_Auth_Adapter_DbTable”

 • PEAR     naming convention

 • Easier   for autoloaders
DEFINING A NAMESPACE

<?php
    namespace MyAppUtil;
    class String
    {
        public function formatPhone($phone) {
            // Regex phone number
            return true;
        }
    }
“USE” A NAMESPACE

<?php
use MyAppUtilString as String;

    $str = new String();
    if ($str->formatPhone('123-456-7890')) {
        echo 'ITS TRUE';
    }
DEFINING MULTIPLE
                 NAMESPACES
One Way                                        Preferred Way!
<?php                                          <?php
use FrameworkController as BaseController     use FrameworkController as BaseController
use FrameworkModel as BaseModel               use FrameworkModel as BaseModel
namespace MyAppControllers;                   namespace MyAppControllers {

class UsersController extends BaseController       class UsersController extends
{                                                  BaseController
                                                   {
}
                                                   }
namespace MyAppUserModel;                     }
class User extends BaseModel
{                                              namespace MyAppUserModel {
                                                   class User extends BaseModel
}                                                  {

                                                   }
                                               }
WHAT IS GLOBAL SCOPE?

• Global   Scope is your “root level” outside of the namespace
       <?php
       namespace Framework;

       class DB
       {
           public function getConnection()
           {
                try {
                    $dbh = new PDO('mysql:dbname=testdb;host=localhost', 'root', 'pass');
                } catch (Exception $e) {
                    echo 'Default Exception';
                }
           }
       }

       $db = new DB();
       $db = $db->getConnection();
ORM EXAMPLE
<?php
    namespace App {
        abstract class Model {
            const TABLE_NAME = '';
            public static function __callStatic($method, $params)
            {
                if (!preg_match('/^(find|findFirst|count)By(w+)$/', $method, $matches)) {
                    throw new Exception("Call to undefined method {$method}");
                }
                echo preg_replace('/([a-z0-9])([A-Z])/', '$1_$2', $matches[2]);
                $criteriaKeys = explode('_And_', preg_replace('/([a-z0-9])([A-Z])/', '$1_$2', $matches[2]));
                print_r($matches);
                $criteriaKeys = array_map('strtolower', $criteriaKeys);
                $criteriaValues = array_slice($params, 0, count($criteriaKeys));
                $criteria = array_combine($criteriaKeys, $criteriaValues);

                $params = array_slice($params, count($criteriaKeys));
                if (count($params) > 0) {
                    list($order, $limit, $offset) = $params;
                }

                $method = $matches[1];
                return static::$method($criteria, $order, $limit, $offset);
            }

            public static function find($criteria = array(), $order = null, $limit = null, $offset = 0)
            {
                echo static::TABLE_NAME;
                echo $order . ' ' . $limit . ' ' . $offset;
            }
        }
    }
    namespace AppModels {
        class Posts extends AppModel
        {
            const TABLE_NAME = 'posts';
        }
    }
QUESTIONS?
THANKS FOR LISTENING
Contact Information
[t]: @jakefolio
[e]: jake@dallasphp.org
[w]: http://www.jakefolio.com

Weitere ähnliche Inhalte

Was ist angesagt?

PHP 良好實踐 (Best Practice)
PHP 良好實踐 (Best Practice)PHP 良好實踐 (Best Practice)
PHP 良好實踐 (Best Practice)Win Yu
 
Dependency Injection with PHP 5.3
Dependency Injection with PHP 5.3Dependency Injection with PHP 5.3
Dependency Injection with PHP 5.3Fabien Potencier
 
Intro to php
Intro to phpIntro to php
Intro to phpSp Singh
 
Php tips-and-tricks4128
Php tips-and-tricks4128Php tips-and-tricks4128
Php tips-and-tricks4128PrinceGuru MS
 
A Functional Guide to Cat Herding with PHP Generators
A Functional Guide to Cat Herding with PHP GeneratorsA Functional Guide to Cat Herding with PHP Generators
A Functional Guide to Cat Herding with PHP GeneratorsMark Baker
 
A Functional Guide to Cat Herding with PHP Generators
A Functional Guide to Cat Herding with PHP GeneratorsA Functional Guide to Cat Herding with PHP Generators
A Functional Guide to Cat Herding with PHP GeneratorsMark Baker
 
The Origin of Lithium
The Origin of LithiumThe Origin of Lithium
The Origin of LithiumNate Abele
 
Perforce Object and Record Model
Perforce Object and Record Model  Perforce Object and Record Model
Perforce Object and Record Model Perforce
 
Corephpcomponentpresentation 1211425966721657-8
Corephpcomponentpresentation 1211425966721657-8Corephpcomponentpresentation 1211425966721657-8
Corephpcomponentpresentation 1211425966721657-8PrinceGuru MS
 
Class 2 - Introduction to PHP
Class 2 - Introduction to PHPClass 2 - Introduction to PHP
Class 2 - Introduction to PHPAhmed Swilam
 
Looping the Loop with SPL Iterators
Looping the Loop with SPL IteratorsLooping the Loop with SPL Iterators
Looping the Loop with SPL IteratorsMark Baker
 
Cli the other SAPI confoo11
Cli the other SAPI confoo11Cli the other SAPI confoo11
Cli the other SAPI confoo11Combell NV
 
Webrtc mojo
Webrtc mojoWebrtc mojo
Webrtc mojobpmedley
 
News of the Symfony2 World
News of the Symfony2 WorldNews of the Symfony2 World
News of the Symfony2 WorldFabien Potencier
 
Static Optimization of PHP bytecode (PHPSC 2017)
Static Optimization of PHP bytecode (PHPSC 2017)Static Optimization of PHP bytecode (PHPSC 2017)
Static Optimization of PHP bytecode (PHPSC 2017)Nikita Popov
 

Was ist angesagt? (20)

PHP 良好實踐 (Best Practice)
PHP 良好實踐 (Best Practice)PHP 良好實踐 (Best Practice)
PHP 良好實踐 (Best Practice)
 
Sorting arrays in PHP
Sorting arrays in PHPSorting arrays in PHP
Sorting arrays in PHP
 
Dependency Injection with PHP 5.3
Dependency Injection with PHP 5.3Dependency Injection with PHP 5.3
Dependency Injection with PHP 5.3
 
Intro to php
Intro to phpIntro to php
Intro to php
 
Php tips-and-tricks4128
Php tips-and-tricks4128Php tips-and-tricks4128
Php tips-and-tricks4128
 
A Functional Guide to Cat Herding with PHP Generators
A Functional Guide to Cat Herding with PHP GeneratorsA Functional Guide to Cat Herding with PHP Generators
A Functional Guide to Cat Herding with PHP Generators
 
A Functional Guide to Cat Herding with PHP Generators
A Functional Guide to Cat Herding with PHP GeneratorsA Functional Guide to Cat Herding with PHP Generators
A Functional Guide to Cat Herding with PHP Generators
 
The Origin of Lithium
The Origin of LithiumThe Origin of Lithium
The Origin of Lithium
 
Current state-of-php
Current state-of-phpCurrent state-of-php
Current state-of-php
 
Data Types In PHP
Data Types In PHPData Types In PHP
Data Types In PHP
 
Symfony2 - WebExpo 2010
Symfony2 - WebExpo 2010Symfony2 - WebExpo 2010
Symfony2 - WebExpo 2010
 
Perforce Object and Record Model
Perforce Object and Record Model  Perforce Object and Record Model
Perforce Object and Record Model
 
Corephpcomponentpresentation 1211425966721657-8
Corephpcomponentpresentation 1211425966721657-8Corephpcomponentpresentation 1211425966721657-8
Corephpcomponentpresentation 1211425966721657-8
 
Class 2 - Introduction to PHP
Class 2 - Introduction to PHPClass 2 - Introduction to PHP
Class 2 - Introduction to PHP
 
Looping the Loop with SPL Iterators
Looping the Loop with SPL IteratorsLooping the Loop with SPL Iterators
Looping the Loop with SPL Iterators
 
Cli the other SAPI confoo11
Cli the other SAPI confoo11Cli the other SAPI confoo11
Cli the other SAPI confoo11
 
Webrtc mojo
Webrtc mojoWebrtc mojo
Webrtc mojo
 
Php functions
Php functionsPhp functions
Php functions
 
News of the Symfony2 World
News of the Symfony2 WorldNews of the Symfony2 World
News of the Symfony2 World
 
Static Optimization of PHP bytecode (PHPSC 2017)
Static Optimization of PHP bytecode (PHPSC 2017)Static Optimization of PHP bytecode (PHPSC 2017)
Static Optimization of PHP bytecode (PHPSC 2017)
 

Andere mochten auch

LESS is More
LESS is MoreLESS is More
LESS is Morejsmith92
 
Drawing the Line with Browser Compatibility
Drawing the Line with Browser CompatibilityDrawing the Line with Browser Compatibility
Drawing the Line with Browser Compatibilityjsmith92
 
Doing more with LESS
Doing more with LESSDoing more with LESS
Doing more with LESSjsmith92
 
Parsimonious Relevance and Concept Models - CLEF 2008 Domain Specific Talk - ...
Parsimonious Relevance and Concept Models - CLEF 2008 Domain Specific Talk - ...Parsimonious Relevance and Concept Models - CLEF 2008 Domain Specific Talk - ...
Parsimonious Relevance and Concept Models - CLEF 2008 Domain Specific Talk - ...Edgar Meij
 
Unsung Heroes of PHP
Unsung Heroes of PHPUnsung Heroes of PHP
Unsung Heroes of PHPjsmith92
 
Intro to Micro-frameworks
Intro to Micro-frameworksIntro to Micro-frameworks
Intro to Micro-frameworksjsmith92
 

Andere mochten auch (6)

LESS is More
LESS is MoreLESS is More
LESS is More
 
Drawing the Line with Browser Compatibility
Drawing the Line with Browser CompatibilityDrawing the Line with Browser Compatibility
Drawing the Line with Browser Compatibility
 
Doing more with LESS
Doing more with LESSDoing more with LESS
Doing more with LESS
 
Parsimonious Relevance and Concept Models - CLEF 2008 Domain Specific Talk - ...
Parsimonious Relevance and Concept Models - CLEF 2008 Domain Specific Talk - ...Parsimonious Relevance and Concept Models - CLEF 2008 Domain Specific Talk - ...
Parsimonious Relevance and Concept Models - CLEF 2008 Domain Specific Talk - ...
 
Unsung Heroes of PHP
Unsung Heroes of PHPUnsung Heroes of PHP
Unsung Heroes of PHP
 
Intro to Micro-frameworks
Intro to Micro-frameworksIntro to Micro-frameworks
Intro to Micro-frameworks
 

Ähnlich wie PHP 5.3 Overview

08 Advanced PHP #burningkeyboards
08 Advanced PHP #burningkeyboards08 Advanced PHP #burningkeyboards
08 Advanced PHP #burningkeyboardsDenis Ristic
 
Can't Miss Features of PHP 5.3 and 5.4
Can't Miss Features of PHP 5.3 and 5.4Can't Miss Features of PHP 5.3 and 5.4
Can't Miss Features of PHP 5.3 and 5.4Jeff Carouth
 
Phpspec tips&amp;tricks
Phpspec tips&amp;tricksPhpspec tips&amp;tricks
Phpspec tips&amp;tricksFilip Golonka
 
Introducing PHP Latest Updates
Introducing PHP Latest UpdatesIntroducing PHP Latest Updates
Introducing PHP Latest UpdatesIftekhar Eather
 
Practical PHP 5.3
Practical PHP 5.3Practical PHP 5.3
Practical PHP 5.3Nate Abele
 
Preparing for the next PHP version (5.6)
Preparing for the next PHP version (5.6)Preparing for the next PHP version (5.6)
Preparing for the next PHP version (5.6)Damien Seguy
 
What's new, what's hot in PHP 5.3
What's new, what's hot in PHP 5.3What's new, what's hot in PHP 5.3
What's new, what's hot in PHP 5.3Jeremy Coates
 
Advanced symfony Techniques
Advanced symfony TechniquesAdvanced symfony Techniques
Advanced symfony TechniquesKris Wallsmith
 
PHP traits, treat or threat?
PHP traits, treat or threat?PHP traits, treat or threat?
PHP traits, treat or threat?Nick Belhomme
 
Mastering Namespaces in PHP
Mastering Namespaces in PHPMastering Namespaces in PHP
Mastering Namespaces in PHPNick Belhomme
 
Frameworks da nova Era PHP FuelPHP
Frameworks da nova Era PHP FuelPHPFrameworks da nova Era PHP FuelPHP
Frameworks da nova Era PHP FuelPHPDan Jesus
 
Aura Project for PHP
Aura Project for PHPAura Project for PHP
Aura Project for PHPHari K T
 
FFW Gabrovo PMG - PHP OOP Part 3
FFW Gabrovo PMG - PHP OOP Part 3FFW Gabrovo PMG - PHP OOP Part 3
FFW Gabrovo PMG - PHP OOP Part 3Toni Kolev
 
02 - Second meetup
02 - Second meetup02 - Second meetup
02 - Second meetupEdiPHP
 

Ähnlich wie PHP 5.3 Overview (20)

08 Advanced PHP #burningkeyboards
08 Advanced PHP #burningkeyboards08 Advanced PHP #burningkeyboards
08 Advanced PHP #burningkeyboards
 
Can't Miss Features of PHP 5.3 and 5.4
Can't Miss Features of PHP 5.3 and 5.4Can't Miss Features of PHP 5.3 and 5.4
Can't Miss Features of PHP 5.3 and 5.4
 
Phpspec tips&amp;tricks
Phpspec tips&amp;tricksPhpspec tips&amp;tricks
Phpspec tips&amp;tricks
 
Introducing PHP Latest Updates
Introducing PHP Latest UpdatesIntroducing PHP Latest Updates
Introducing PHP Latest Updates
 
Practical PHP 5.3
Practical PHP 5.3Practical PHP 5.3
Practical PHP 5.3
 
Preparing for the next PHP version (5.6)
Preparing for the next PHP version (5.6)Preparing for the next PHP version (5.6)
Preparing for the next PHP version (5.6)
 
php AND MYSQL _ppt.pdf
php AND MYSQL _ppt.pdfphp AND MYSQL _ppt.pdf
php AND MYSQL _ppt.pdf
 
What's new, what's hot in PHP 5.3
What's new, what's hot in PHP 5.3What's new, what's hot in PHP 5.3
What's new, what's hot in PHP 5.3
 
Solid principles
Solid principlesSolid principles
Solid principles
 
Advanced symfony Techniques
Advanced symfony TechniquesAdvanced symfony Techniques
Advanced symfony Techniques
 
Modern php
Modern phpModern php
Modern php
 
Fatc
FatcFatc
Fatc
 
PHP traits, treat or threat?
PHP traits, treat or threat?PHP traits, treat or threat?
PHP traits, treat or threat?
 
Mastering Namespaces in PHP
Mastering Namespaces in PHPMastering Namespaces in PHP
Mastering Namespaces in PHP
 
Frameworks da nova Era PHP FuelPHP
Frameworks da nova Era PHP FuelPHPFrameworks da nova Era PHP FuelPHP
Frameworks da nova Era PHP FuelPHP
 
Oops in php
Oops in phpOops in php
Oops in php
 
Aura Project for PHP
Aura Project for PHPAura Project for PHP
Aura Project for PHP
 
FFW Gabrovo PMG - PHP OOP Part 3
FFW Gabrovo PMG - PHP OOP Part 3FFW Gabrovo PMG - PHP OOP Part 3
FFW Gabrovo PMG - PHP OOP Part 3
 
Ch8(oop)
Ch8(oop)Ch8(oop)
Ch8(oop)
 
02 - Second meetup
02 - Second meetup02 - Second meetup
02 - Second meetup
 

Kürzlich hochgeladen

Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 
Generative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfGenerative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfIngrid Airi González
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxLoriGlavin3
 
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...panagenda
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .Alan Dix
 
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality AssuranceInflectra
 
Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Hiroshi SHIBATA
 
Scale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterScale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterMydbops
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxLoriGlavin3
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxLoriGlavin3
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...Wes McKinney
 
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentEmixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentPim van der Noll
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersNicole Novielli
 
UiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPathCommunity
 
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfSo einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfpanagenda
 
Testing tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesTesting tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesKari Kakkonen
 
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesHow to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesThousandEyes
 

Kürzlich hochgeladen (20)

Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 
Generative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfGenerative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdf
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
 
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
 
Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024
 
Scale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterScale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL Router
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
 
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentEmixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software Developers
 
UiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to Hero
 
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfSo einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
 
Testing tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesTesting tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examples
 
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesHow to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
 

PHP 5.3 Overview

  • 1. PHP 5.3 OVERVIEW 6/8/2010 - Dallas PHP Jake Smith
  • 2. PERFORMANCE • Over 140 bug fixes • 40%+ improvement with PHP on Windows • 5% - 15% overall performance improvement • MD5 roughly 15% faster • Constants move to read-only memory • Drupal 20% faster, Wordpress 15% faster
  • 3. ADDITIONS • New error_reporting E_DEPRECATED • Garbage collection • MySQLnd (Native Driver) • No longer uses libmysql • No PDO support (currently) • MySQL version 4.1+
  • 4. BACKWARDS COMPATIBILITY • EREG Family is now E_DEPRECATED • Use the Pearl Compatible (PCRE) • __toString does not accept arguments/parameters • Magic methods must be public and can not be static • __call is now invoked on access to private/protected methods • Classes can not be named Namespace or Closure SOURCES: http://us2.php.net/manual/en/migration53.incompatible.php
  • 5. MAGIC METHODS IN 5.3 <?php class Backwards { public function __call($method, $value) { echo "Call Magic Method<br />n"; } private function __get($method) { } private function __set($method, $value) { } private function getElements() { echo "Get Elements<br />n"; } } $bc = new Backwards(); $bc->getElements();
  • 6. CHANGES IN PHP.INI • INI Variables • Per Folder/Per Site ini settings • User specified ini files
  • 7. .INI VARIABLES error_dev = E_ALL error_prod = E_NONE [HOST=dev.mydomain.com] error_reporting = ${error_dev} [HOST=mydomain.com] error_reporting = ${error_prod} [PATH=/var/www/vhosts/myotherdomain.com] error_reporting = ${error_prod} # User Defined ini. Place in web root. Set to blank to disable user_ini.filename = .user.ini user_ini.cache_ttl = 300
  • 8. SLOW ADOPTION • Open Source projects were initially not compatible with PHP 5.3 • Currentlymost major Open Source software (Wordpress, Drupal, Joomla and Magento) work in PHP 5.3 • Key plugins are lacking behind
  • 9. PECL ADDITIONS • PECL Added • FileInfo, Intl, Phar, MySQLnd, SQLite3 • PECL Removed • ncurses, FPDF, dbase, fbsql, ming SOURCES: http://php.net/releases/5_3_0.php
  • 10. SPL ADDITIONS • GlobIterator - Iterator utilizing glob, look up glob function • SplFixedArray - Fixed size/dimension array • SplQueue • SplHeap • SplStack SOURCES: http://matthewturland.com/2010/05/20/new-spl-features-in-php-5-3/
  • 11. NEW CONSTANTS • __DIR__ • No more dirname(__FILE__); • __NAMESPACE__ • Current namespace
  • 12. NEW OPERATORS • Ternary Operator ?: • Goto • NOWDOC
  • 13. TERNARY OPERATOR <?php // Before PHP 5.3 $action = $_POST['action'] ? $_POST['action'] : 'Default Action'; // Now in PHP 5.3 (less time) $action = $_POST['action'] ?: 'Default Action';
  • 15. GOTO EXAMPLE <?php for($i=0,$j=50; $i<100; $i++) { while($j--) { if($j==17) goto end; } } echo "i = $i"; end: // End echo 'j hit 17'; SOURCES: http://php.net/manual/en/control-structures.goto.php
  • 16. NOWDOC VS. HEREDOC • NOWDOC works just like HEREDOC, except it does not evaluate PHP variables <?php $myVar = 'testing'; // OUTPUT: Here is my text testing $longString = <<<HEREDOC Here is my text $myVar HEREDOC; // OUTPUT: Here is my text $myVar $longString = <<<'NOWDOC' Here is my text $myVar 'NOWDOC';
  • 17. DATE/TIME OBJECT ADDITIONS • New functions/methods added to Date/Time Object • date_add, date_sub and date_diff <?php $date = new DateTime('2000-01-01'); $date->add(new DateInterval('P10D')); echo $date->format('Y-m-d') . "n"; // OR $date = date_create('200-01-01'); date_add($date, date_interval_create_from_date_string('10 days')); echo date_format($date, 'Y-m-d'); SOURCES: http://www.php.net/manual/en/class.datetime.php
  • 18. NEW METHODS • Functors/__invoke • Dynamic Static Method • __callStatic • get_called_class()
  • 19. __INVOKE <?php class Functor { public function __invoke($param = null) { return 'Hello Param: ' . $param; } } $func = new Functor(); echo $func('PHP 5.3'); // Hello Param: PHP 5.3
  • 20. DYNAMIC STATIC METHOD <?php abstract class Model { const TABLE_NAME = ''; public static function __call($method, $params) { // Run logic return $this->$method($criteria, $order, $limit, $offset); } }
  • 21. DYNAMIC STATIC METHOD <?php abstract class Model { const TABLE_NAME = ''; public static function __callStatic($method, $params) { // Run logic return static::$method($criteria, $order, $limit, $offset); } }
  • 22. __CALLSTATIC • __callStatic works exactly like __call, except it’s a static method • Acts as a catch all for all undefined methods (get or set) <?php abstract class Model { const TABLE_NAME = ''; public static function __callStatic($method, $params) { // Run logic return static::$method($criteria, $order, $limit, $offset); } }
  • 23. GET_CLASS_CALLED • get_called_class returns the class name that called on the parent method
  • 24. GET_CLASS_CALLED <?php namespace App { abstract class Model { public static function __callStatic($method, $params) { // Search Logic $method = $matches[1]; return static::$method($criteria, $order, $limit, $offset); } public static function find($criteria = array(), $order = null, $limit = null, $offset = 0) { $tableName = strtolower(get_class_called()); // get_class_called will return Post } } } namespace AppModels { class Post extends AppModel {} } // Returns all the posts that contain Dallas PHP in the title $posts = Post::findByTitle('Dallas PHP'); ?>
  • 25. LATE STATIC BINDING • This feature was named "late static bindings" with an internal perspective in mind. "Late binding" comes from the fact that static:: will no longer be resolved using the class where the method is defined but it will rather be computed using runtime information. SOURCES: http://us.php.net/lsb
  • 26. LSB BEFORE PHP 5.3 <?php class Model { const TABLE_NAME = ''; public static function getTable() { return self::TABLE_NAME; } } class Author extends Model { const TABLE_NAME = 'Author'; } class Post extends Model { const TABLE_NAME = 'Post' } // sadly you get nothing echo Post::TABLE_NAME;
  • 27. LSB PHP 5.3.X • static keyword to save the day! <?php class Model { const TABLE_NAME = ''; public static function getTable() { return static::TABLE_NAME; } } class Author extends Model { const TABLE_NAME = 'Author'; } class Post extends Model { const TABLE_NAME = 'Post' } // sadly you get nothing echo Post::TABLE_NAME;
  • 28. LAMBDA IN PHP 5.3 • Anonymous functions, also known as closures, allow the creation of functions which have no specified name. They are most useful as the value of callback parameters, but they have many other uses. • Good function examples: array_map() and array_walk() <?php $string = 'Testing'; $array = array('hello', 'world', 'trying', 'PHP 5.3'); $return = array_walk($array, function($v,$k) { echo ucwords($v); });
  • 29. LAMBDA EXAMPLE (JQUERY) $('.button').click(function() { $(this).hide(); });
  • 30. CLOSURE <?php // Cycle factory: takes a series of arguments // for the closure to cycle over. function getRowColor (array $colors) { $i = 0; $max = count($colors); $colors = array_values($colors); $color = function() use (&$i, $max, $colors) { $color = $colors[$i]; $i = ($i + 1) % $max; return $color; }; return $color; } $rowColor = getRowColor(array('#FFF', '#F00', '#000')); echo $rowColor() . '<br />'; echo $rowColor() . '<br />'; echo $rowColor() . '<br />'; echo $rowColor() . '<br />'; echo $rowColor() . '<br />'; echo $rowColor() . '<br />';
  • 31. NAMESPACES • Before PHP 5.3 • PHP didn’t have namespaces, so we created a standard: “Zend_Auth_Adapter_DbTable” • PEAR naming convention • Easier for autoloaders
  • 32. DEFINING A NAMESPACE <?php namespace MyAppUtil; class String { public function formatPhone($phone) { // Regex phone number return true; } }
  • 33. “USE” A NAMESPACE <?php use MyAppUtilString as String; $str = new String(); if ($str->formatPhone('123-456-7890')) { echo 'ITS TRUE'; }
  • 34. DEFINING MULTIPLE NAMESPACES One Way Preferred Way! <?php <?php use FrameworkController as BaseController use FrameworkController as BaseController use FrameworkModel as BaseModel use FrameworkModel as BaseModel namespace MyAppControllers; namespace MyAppControllers { class UsersController extends BaseController class UsersController extends { BaseController { } } namespace MyAppUserModel; } class User extends BaseModel { namespace MyAppUserModel { class User extends BaseModel } { } }
  • 35. WHAT IS GLOBAL SCOPE? • Global Scope is your “root level” outside of the namespace <?php namespace Framework; class DB { public function getConnection() { try { $dbh = new PDO('mysql:dbname=testdb;host=localhost', 'root', 'pass'); } catch (Exception $e) { echo 'Default Exception'; } } } $db = new DB(); $db = $db->getConnection();
  • 36. ORM EXAMPLE <?php namespace App { abstract class Model { const TABLE_NAME = ''; public static function __callStatic($method, $params) { if (!preg_match('/^(find|findFirst|count)By(w+)$/', $method, $matches)) { throw new Exception("Call to undefined method {$method}"); } echo preg_replace('/([a-z0-9])([A-Z])/', '$1_$2', $matches[2]); $criteriaKeys = explode('_And_', preg_replace('/([a-z0-9])([A-Z])/', '$1_$2', $matches[2])); print_r($matches); $criteriaKeys = array_map('strtolower', $criteriaKeys); $criteriaValues = array_slice($params, 0, count($criteriaKeys)); $criteria = array_combine($criteriaKeys, $criteriaValues); $params = array_slice($params, count($criteriaKeys)); if (count($params) > 0) { list($order, $limit, $offset) = $params; } $method = $matches[1]; return static::$method($criteria, $order, $limit, $offset); } public static function find($criteria = array(), $order = null, $limit = null, $offset = 0) { echo static::TABLE_NAME; echo $order . ' ' . $limit . ' ' . $offset; } } } namespace AppModels { class Posts extends AppModel { const TABLE_NAME = 'posts'; } }
  • 38. THANKS FOR LISTENING Contact Information [t]: @jakefolio [e]: jake@dallasphp.org [w]: http://www.jakefolio.com