SlideShare una empresa de Scribd logo
1 de 29
Descargar para leer sin conexión
INTRODUCING PHP 5.3
   PHP Quebec 2008 - Ilia Alshanetsky




                                        1
EVOLUTIONARY
         RELEASE
Old code will still work
Focus on mainly
improvement of
existing functionality
Fewer bugs
Faster release cycle



                           2
Namespaces

Biggest addition in 5.3 code base
Feature complete implementation of namespaces
Majority of functionality implemented at compile time
Simplifies naming conventions




                                                        3
Cleaner Code
Without Namespaces                 With Namespaces
function MY_wrapper() {}           namespace MY;

class MY_DB { }                    function wrapper() {}

define('MY_CONN_STR', '');         class DB { }

                                   const CONN_STR = '';
                           +   =
                                   use MY AS MY;
MY_wrapper();
                                   wrapper();
new MY_DB();
                                   new DB();
MY_CONN_STR;
                                   CONN_STR;



                                                           4
Multiple Namespaces Per File
namespace LIB;

class MySQL {}
class SQLite {}

$b = new SQLite();
                         string(18) quot;LIB_EXTRA::MScryptquot;
namespace LIB_EXTRA;     string(11) quot;LIB::SQLitequot;

class MScrypt {}

$a = new MScrypt();


var_dump(
        get_class($a),
        get_class($b)
);


                                                           5
Namespace Hierarchy
namespace foo;

function strlen($foo) { return htmlentities($foo); }

echo strlen(quot;testquot;); // test 
echo ::strlen(quot;testquot;); // 4
echo namespace::strlen(quot;testquot;); // test



 Function, class and constant references inside a
 namespace refer to namespace first and global scope
 later.



                                                       6
Namespaces & autoload
function __autoload($var) { var_dump($var); } // LIB::foo
require quot;./ns.phpquot;; /*
        <?php
                namespace LIB;
                new foo();
*/



    __autoload() will be passed namespace name along with
    class name.

    autoload will only be triggered if class does not exist in
    namespace and global scope

    __autoload() declared inside a namespace will not be
    called!

                                                                 7
Other NS Syntactic Sugar
namespace really::long::pointlessly::verbose::ns;  

__NAMESPACE__; // current namespace name       

class a{}   

get_class(new a()); // really::long::pointlessly::verbose::ns::a

use really::long::pointlessly::verbose::ns::a AS b;
                                                  Reference class from a
                                                       namespace




                                                                           8
Improved Performance
md5() is roughly 10-15% faster
Better stack implementation in the engine
Constants moved to read-only memory
Improve exception handling (simpler & less opcodes)
Eliminate open(2) call on (require/include)_once
Smaller binary size & startup size with gcc4

          Overall Improvement 5-15%


                                                      9
New Language Features




                        10
__DIR__
Introduced __DIR__ magic constant indicating the
directory where the script is located.


        echo dirname(__FILE__); // < PHP 5.3

            /* vs */

        echo __DIR__; // >= PHP 5.3




                                                   11
?: Operator
Allows quick retrieval of a non-empty value from 2
values and/or expressions
        $a = true ?: false; // true
        $a = false ?: true; // true
        $a = quot;quot; ?: 1; // 1
        $a = 0 ?: 2; // 2
        $a = array() ?: array(1); // array(1);
        $a = strlen(quot;quot;) ?: strlen(quot;aquot;); // 1




                                                     12
__callStatic()
__call() equivalent, but for static methods.

class helper {
        static function __callStatic($name, $args) {
                echo $name.'('.implode(',', $args).')';
        }
}

helper::test(quot;fooquot;,quot;barquot;); // test(foo,bar)




         ✴   Dynamic function/method calls are kinda slow...



                                                               13
Dynamic Static Calls
PHP now allows dynamic calls to static methods

  class helper {
          static function foo() { echo __METHOD__; }
  }

  $a = quot;helperquot;;
  $b = quot;fooquot;;

  $a::$b(); // helper::foo




        ✴   Dynamic function/method calls are kinda slow...



                                                              14
Late Static Binding
     Processing of static events has been extended into
     execution time from compile time.
class A {                                  class A {
   public static function whoami() {          public static function whoami() {
      echo __CLASS__;                            echo __CLASS__;
   }                                          }

   public static function identity() {        public static function identity() {
     self::whoami();                             static::whoami();
   }                                          }
}                                          }

class B extends A {                        class B extends A {
   public static function whoami() {          public static function whoami() {
      echo __CLASS__;                            echo __CLASS__;
   }                                          }
}                                          }

B::identity(); // A <-- PHP < 5.3          B::identity(); // B <-- >= PHP 5.3

                      ✴   Beware if you use an opcode cache
                      ✴   Not backwards compatible

                                                                                    15
MySQLInd
Specialized, high speed library to interface with
MySQL designed specifically for PHP

           mysql_fetch_assoc(quot;...quot;);

             ext/mysql                                         ext/mysql
                                                         Copy of data in PHP

         Copy on Write in
            mysqlind                                       Copy in libmysql
      Row Data   Row Data   Row Data                    Row Data   Row Data   Row Data




                                       MySQL Database




                                                                                         16
MySQLInd
Better performance
Improved memory usage
Ability to fetch statistics for performance tuning
Built-in driver (no external decencies once again)
Many future options due to tight integration with PHP
No PDO_MySQL support yet, mysql(i) only for now




                                                        17
INI Magic
Support for “.htaccess” style INI controls for CGI/
FastCGI
Per-directory INI settings inside php.ini via
[PATH=/var/www/domain.com] not modifiable by the
user.
Improve error handling
Allow use of INI variables and constants from virtually
everywhere in the INI files
Several other minor improvements

                                                          18
INI Magic
Name for user-defined php.ini (.htaccess) files. Default is quot;.user.iniquot;
user_ini.filename = quot;.user.iniquot;

To disable this feature set this option to empty value
user_ini.filename =

TTL for user-defined php.ini files (time-to-live) in seconds.
Default is 300 seconds (5 minutes)
user_ini.cache_ttl = 300

[PATH=/var/www/domain.com]
variables_order = GPC
safe_mode = 1

[my variables]
somevar = “1234”
anothervar = ${somevar} ; anothervar == somevar

[ini arrays]
foo[bar] = 1
foo[123] = 2
foo[] = 3


                                                                          19
Extra OpenSSL Functions
    Access to OpenSSL Digest Functions
foreach (openssl_get_md_methods() as $d) {// MD4, MD5, SHA512... (12 all in all)
  echo $d.quot; - quot;.openssl_digest(quot;fooquot;, quot;md5quot;); //acbd18db4cc2f85cedef654fccc4a4d8
}

    Access to OpenSSL Cipher Functions
               // BF-CBC, AES-256 CFB1... (54 all in all)
               foreach(openssl_get_cipher_methods() as $v) {
                 $val = openssl_encrypt(quot;valuequot;, $v, quot;secretquot;);
                 openssl_decrypt($val, $v, quot;secretquot;); // value   
               }


    Extend openssl_pkey_new() and openssl_pkey_get_details()
    functions to allow access to internal DSA, RSA and DH
    keys.

The goal was to simply OpenID implementation in PHP

                                                                                   20
SPL Improvements
Improve nested directory iterations via
FilesystemIterator
Introduced GlobIterator
Various data structure classes: SplDoublyLinkedList,
SplStack, SplQueue, SplHeap, SplMinHeap,
SplMaxHeap, SplPriorityQueue
Several other tongue twister features




                                                       21
Date Extension Additions
Controllable strtotime() via date_create_from_format()
  $date = strtotime(quot;08-01-07 00:00:00quot;);
  var_dump(date(quot;Y-m-dquot;, $date)); // string(10) quot;2008-01-07quot;
  $date = date_create_from_format(quot;m-d-yquot;, quot;08-01-07quot;);
  var_dump($date->format('Y-m-d')); // string(10) quot;2007-08-01quot;


Added date_get_last_errors() that returns errors and
warnings in date parsing.
 array(4) {
   [quot;warning_countquot;] => int(0)
   [quot;warningsquot;] => array(0) { }
   [quot;error_countquot;] => int(2)
   [quot;errorsquot;]=>
   array(2) {
     [2]=> string(40) quot;The separation symbol could not be foundquot;
     [6]=> string(13) quot;Trailing dataquot;
   }
 }




                                                                   22
getopt() Improvements
Works on Windows
Native implementation not dependent on native
getopt() implementation.
Cross-platform support for longopts (--option)
        // input: --a=foo --b --c
        var_dump(getopt(quot;quot;, array(quot;a:quot;,quot;b::quot;,quot;cquot;)));
        /* output: array(3) {
          [quot;aquot;]=>
          string(3) quot;fooquot;
          [quot;bquot;]=>
          bool(false)
          [quot;cquot;]=>
          bool(false)
        } */




                                                       23
XSLT Profiling
 Introduction of Xslt Profiling via setProfiling()

          $xslt = new xsltprocessor(); 
          $xslt->importStylesheet($xml); 
          $xslt->setProfiling(quot;/tmp/profile.txtquot;); 
          $xslt->transformToXml($dom);


                      Resulting In:

number        match              name     mode   Calls Tot 100us Avg

   0           date                                   5    58     11

                  Total                               5    58




                                                                       24
E_DEPRECATED

What would a PHP release be without a new error
mode? deprecated


Used to designate deprecated functionality that maybe,
sometime in a far future will get removed, maybe.




                                                         25
Garbage Collector
Memory cleanup for Über-complex and long scripts
that need to free-up memory before the end of
execution cycle. (!amework folks, this is for you)

  gc_enable(); // Enable Garbage Collector

  var_dump(gc_enabled()); // true

  var_dump(gc_collect_cycles()); // # of elements cleaned up

  gc_disable(); // Disable Garbage Collector




                                                               26
NOWDOC
 A HEREDOC where no escaping is necessary


     HEREDOC                         NOWDOC
$foo = <<<ONE                $bar = <<<‘TWO’
this is $fubar               this is $fubar
ONE;                         TWO;
    
/* string(10) quot;this isquot; */   /* string(16) quot;this is $fubarquot; */




                                                                 27
Miscellaneous Improvements

 SQLite Upgraded to 3.5.6
 Over 40 bug fixes
 CGI/FastCGI SAPI Improvements
 Various stream improvements
 More things to come ...




                                 28
Thank You For Listening


          Questions?


  These slides can be found on: http://ilia.ws


                                                 29

Más contenido relacionado

La actualidad más candente

Understanding PHP objects
Understanding PHP objectsUnderstanding PHP objects
Understanding PHP objects
julien pauli
 
SPL: The Missing Link in Development
SPL: The Missing Link in DevelopmentSPL: The Missing Link in Development
SPL: The Missing Link in Development
jsmith92
 
Building Web Services with Zend Framework (PHP Benelux meeting 20100713 Vliss...
Building Web Services with Zend Framework (PHP Benelux meeting 20100713 Vliss...Building Web Services with Zend Framework (PHP Benelux meeting 20100713 Vliss...
Building Web Services with Zend Framework (PHP Benelux meeting 20100713 Vliss...
King Foo
 

La actualidad más candente (19)

Agile Memcached
Agile MemcachedAgile Memcached
Agile Memcached
 
Perl 20tips
Perl 20tipsPerl 20tips
Perl 20tips
 
Understanding PHP objects
Understanding PHP objectsUnderstanding PHP objects
Understanding PHP objects
 
Php on the Web and Desktop
Php on the Web and DesktopPhp on the Web and Desktop
Php on the Web and Desktop
 
SPL: The Missing Link in Development
SPL: The Missing Link in DevelopmentSPL: The Missing Link in Development
SPL: The Missing Link in Development
 
Php MySql For Beginners
Php MySql For BeginnersPhp MySql For Beginners
Php MySql For Beginners
 
Php in 2013 (Web-5 2013 conference)
Php in 2013 (Web-5 2013 conference)Php in 2013 (Web-5 2013 conference)
Php in 2013 (Web-5 2013 conference)
 
Oracle database - Get external data via HTTP, FTP and Web Services
Oracle database - Get external data via HTTP, FTP and Web ServicesOracle database - Get external data via HTTP, FTP and Web Services
Oracle database - Get external data via HTTP, FTP and Web Services
 
What you need to remember when you upload to CPAN
What you need to remember when you upload to CPANWhat you need to remember when you upload to CPAN
What you need to remember when you upload to CPAN
 
Language enhancement in ColdFusion 8
Language enhancement in ColdFusion 8Language enhancement in ColdFusion 8
Language enhancement in ColdFusion 8
 
Mysqlnd, an unknown powerful PHP extension
Mysqlnd, an unknown powerful PHP extensionMysqlnd, an unknown powerful PHP extension
Mysqlnd, an unknown powerful PHP extension
 
Php 26
Php 26Php 26
Php 26
 
Streams, sockets and filters oh my!
Streams, sockets and filters oh my!Streams, sockets and filters oh my!
Streams, sockets and filters oh my!
 
typemap in Perl/XS
typemap in Perl/XS  typemap in Perl/XS
typemap in Perl/XS
 
Beyond php - it's not (just) about the code
Beyond php - it's not (just) about the codeBeyond php - it's not (just) about the code
Beyond php - it's not (just) about the code
 
PostgreSQL and PL/Java
PostgreSQL and PL/JavaPostgreSQL and PL/Java
PostgreSQL and PL/Java
 
Building Web Services with Zend Framework (PHP Benelux meeting 20100713 Vliss...
Building Web Services with Zend Framework (PHP Benelux meeting 20100713 Vliss...Building Web Services with Zend Framework (PHP Benelux meeting 20100713 Vliss...
Building Web Services with Zend Framework (PHP Benelux meeting 20100713 Vliss...
 
Php Development With Eclipde PDT
Php Development With Eclipde PDTPhp Development With Eclipde PDT
Php Development With Eclipde PDT
 
PHP - PDO Objects
PHP - PDO ObjectsPHP - PDO Objects
PHP - PDO Objects
 

Destacado

My Works About UT Plan (draft) 2006
My Works About UT Plan (draft) 2006My Works About UT Plan (draft) 2006
My Works About UT Plan (draft) 2006
Ruby Kuo
 
обезлесяването в българия
обезлесяването в българияобезлесяването в българия
обезлесяването в българия
Rositsa Dimova
 
Rooster Voorzitten En Notuleren
Rooster Voorzitten En NotulerenRooster Voorzitten En Notuleren
Rooster Voorzitten En Notuleren
guestd390b9
 
Pavilion N Bbrochure
Pavilion N BbrochurePavilion N Bbrochure
Pavilion N Bbrochure
guesta00b88
 
VIBEWELL Hard Chrome Process
VIBEWELL Hard Chrome Process VIBEWELL Hard Chrome Process
VIBEWELL Hard Chrome Process
flyrr
 
Rc064 010d Core Html 1
Rc064 010d Core Html 1Rc064 010d Core Html 1
Rc064 010d Core Html 1
troopergreen
 
11 may 2015 the evolution of the public research organisations and traditio...
11 may 2015   the evolution of the public research organisations and traditio...11 may 2015   the evolution of the public research organisations and traditio...
11 may 2015 the evolution of the public research organisations and traditio...
Mohamed Larbi BEN YOUNES
 

Destacado (20)

12 may 2015 les politiques de recherche et d’innovation dans les pays de l’...
12 may 2015   les politiques de recherche et d’innovation dans les pays de l’...12 may 2015   les politiques de recherche et d’innovation dans les pays de l’...
12 may 2015 les politiques de recherche et d’innovation dans les pays de l’...
 
My Works About UT Plan (draft) 2006
My Works About UT Plan (draft) 2006My Works About UT Plan (draft) 2006
My Works About UT Plan (draft) 2006
 
Inergy
InergyInergy
Inergy
 
обезлесяването в българия
обезлесяването в българияобезлесяването в българия
обезлесяването в българия
 
Hack the Hood: Transforming Youth & Local Small Business through Project-Base...
Hack the Hood: Transforming Youth & Local Small Business through Project-Base...Hack the Hood: Transforming Youth & Local Small Business through Project-Base...
Hack the Hood: Transforming Youth & Local Small Business through Project-Base...
 
Rooster Voorzitten En Notuleren
Rooster Voorzitten En NotulerenRooster Voorzitten En Notuleren
Rooster Voorzitten En Notuleren
 
FLOW3-Workshop F3X12
FLOW3-Workshop F3X12FLOW3-Workshop F3X12
FLOW3-Workshop F3X12
 
Manga Madness!!! Graphic Fiction For Teens
Manga Madness!!! Graphic Fiction For TeensManga Madness!!! Graphic Fiction For Teens
Manga Madness!!! Graphic Fiction For Teens
 
Inergy
InergyInergy
Inergy
 
Pavilion N Bbrochure
Pavilion N BbrochurePavilion N Bbrochure
Pavilion N Bbrochure
 
137 sou
137 sou137 sou
137 sou
 
Re&agri 2014 growing power exploring energy needs in smallholder agricultur...
Re&agri 2014   growing power exploring energy needs in smallholder agricultur...Re&agri 2014   growing power exploring energy needs in smallholder agricultur...
Re&agri 2014 growing power exploring energy needs in smallholder agricultur...
 
VIBEWELL Hard Chrome Process
VIBEWELL Hard Chrome Process VIBEWELL Hard Chrome Process
VIBEWELL Hard Chrome Process
 
ITALIAN STUDENTS PRESENTED
ITALIAN STUDENTS PRESENTEDITALIAN STUDENTS PRESENTED
ITALIAN STUDENTS PRESENTED
 
Rc064 010d Core Html 1
Rc064 010d Core Html 1Rc064 010d Core Html 1
Rc064 010d Core Html 1
 
11 may 2015 the evolution of the public research organisations and traditio...
11 may 2015   the evolution of the public research organisations and traditio...11 may 2015   the evolution of the public research organisations and traditio...
11 may 2015 the evolution of the public research organisations and traditio...
 
Virussen Pp De Goeie
Virussen Pp De GoeieVirussen Pp De Goeie
Virussen Pp De Goeie
 
02 - Le Rôle des Grappes dans la Stratégie de Spécialisation Intelligente
02 - Le Rôle des Grappes dans la Stratégie de Spécialisation Intelligente02 - Le Rôle des Grappes dans la Stratégie de Spécialisation Intelligente
02 - Le Rôle des Grappes dans la Stratégie de Spécialisation Intelligente
 
Lazarovden1
Lazarovden1Lazarovden1
Lazarovden1
 
SharePoint 2010 - The Business Collaboration Platform
SharePoint 2010 - The Business Collaboration PlatformSharePoint 2010 - The Business Collaboration Platform
SharePoint 2010 - The Business Collaboration Platform
 

Similar a Introduction to PHP 5.3

Introducing PHP Latest Updates
Introducing PHP Latest UpdatesIntroducing PHP Latest Updates
Introducing PHP Latest Updates
Iftekhar Eather
 
4069180 Caching Performance Lessons From Facebook
4069180 Caching Performance Lessons From Facebook4069180 Caching Performance Lessons From Facebook
4069180 Caching Performance Lessons From Facebook
guoqing75
 
High Performance Django 1
High Performance Django 1High Performance Django 1
High Performance Django 1
DjangoCon2008
 
High Performance Django
High Performance DjangoHigh Performance Django
High Performance Django
DjangoCon2008
 
Remedie: Building a desktop app with HTTP::Engine, SQLite and jQuery
Remedie: Building a desktop app with HTTP::Engine, SQLite and jQueryRemedie: Building a desktop app with HTTP::Engine, SQLite and jQuery
Remedie: Building a desktop app with HTTP::Engine, SQLite and jQuery
Tatsuhiko Miyagawa
 
10 Things Every Plugin Developer Should Know (WordCamp Atlanta 2013)
10 Things Every Plugin Developer Should Know (WordCamp Atlanta 2013)10 Things Every Plugin Developer Should Know (WordCamp Atlanta 2013)
10 Things Every Plugin Developer Should Know (WordCamp Atlanta 2013)
arcware
 

Similar a Introduction to PHP 5.3 (20)

Building Testable PHP Applications
Building Testable PHP ApplicationsBuilding Testable PHP Applications
Building Testable PHP Applications
 
Introducing PHP Latest Updates
Introducing PHP Latest UpdatesIntroducing PHP Latest Updates
Introducing PHP Latest Updates
 
Pecl Picks
Pecl PicksPecl Picks
Pecl Picks
 
Lithium: The Framework for People Who Hate Frameworks, Tokyo Edition
Lithium: The Framework for People Who Hate Frameworks, Tokyo EditionLithium: The Framework for People Who Hate Frameworks, Tokyo Edition
Lithium: The Framework for People Who Hate Frameworks, Tokyo Edition
 
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
 
4069180 Caching Performance Lessons From Facebook
4069180 Caching Performance Lessons From Facebook4069180 Caching Performance Lessons From Facebook
4069180 Caching Performance Lessons From Facebook
 
Service discovery and configuration provisioning
Service discovery and configuration provisioningService discovery and configuration provisioning
Service discovery and configuration provisioning
 
Sql php-vibrant course-mumbai(1)
Sql php-vibrant course-mumbai(1)Sql php-vibrant course-mumbai(1)
Sql php-vibrant course-mumbai(1)
 
関西PHP勉強会 php5.4つまみぐい
関西PHP勉強会 php5.4つまみぐい関西PHP勉強会 php5.4つまみぐい
関西PHP勉強会 php5.4つまみぐい
 
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)
 
Fatc
FatcFatc
Fatc
 
Built-in query caching for all PHP MySQL extensions/APIs
Built-in query caching for all PHP MySQL extensions/APIsBuilt-in query caching for all PHP MySQL extensions/APIs
Built-in query caching for all PHP MySQL extensions/APIs
 
Api Design
Api DesignApi Design
Api Design
 
Mastering Namespaces in PHP
Mastering Namespaces in PHPMastering Namespaces in PHP
Mastering Namespaces in PHP
 
High Performance Django 1
High Performance Django 1High Performance Django 1
High Performance Django 1
 
High Performance Django
High Performance DjangoHigh Performance Django
High Performance Django
 
Innovative Specifications for Better Performance Logging and Monitoring
Innovative Specifications for Better Performance Logging and MonitoringInnovative Specifications for Better Performance Logging and Monitoring
Innovative Specifications for Better Performance Logging and Monitoring
 
Remedie: Building a desktop app with HTTP::Engine, SQLite and jQuery
Remedie: Building a desktop app with HTTP::Engine, SQLite and jQueryRemedie: Building a desktop app with HTTP::Engine, SQLite and jQuery
Remedie: Building a desktop app with HTTP::Engine, SQLite and jQuery
 
10 Things Every Plugin Developer Should Know (WordCamp Atlanta 2013)
10 Things Every Plugin Developer Should Know (WordCamp Atlanta 2013)10 Things Every Plugin Developer Should Know (WordCamp Atlanta 2013)
10 Things Every Plugin Developer Should Know (WordCamp Atlanta 2013)
 
Php Security
Php SecurityPhp Security
Php Security
 

Último

EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
Earley Information Science
 

Último (20)

Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
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
 
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
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
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
 
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
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
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...
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 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...
 

Introduction to PHP 5.3

  • 1. INTRODUCING PHP 5.3 PHP Quebec 2008 - Ilia Alshanetsky 1
  • 2. EVOLUTIONARY RELEASE Old code will still work Focus on mainly improvement of existing functionality Fewer bugs Faster release cycle 2
  • 3. Namespaces Biggest addition in 5.3 code base Feature complete implementation of namespaces Majority of functionality implemented at compile time Simplifies naming conventions 3
  • 4. Cleaner Code Without Namespaces With Namespaces function MY_wrapper() {} namespace MY; class MY_DB { } function wrapper() {} define('MY_CONN_STR', ''); class DB { } const CONN_STR = ''; + = use MY AS MY; MY_wrapper(); wrapper(); new MY_DB(); new DB(); MY_CONN_STR; CONN_STR; 4
  • 5. Multiple Namespaces Per File namespace LIB; class MySQL {} class SQLite {} $b = new SQLite(); string(18) quot;LIB_EXTRA::MScryptquot; namespace LIB_EXTRA; string(11) quot;LIB::SQLitequot; class MScrypt {} $a = new MScrypt(); var_dump(         get_class($a),         get_class($b) ); 5
  • 7. Namespaces & autoload function __autoload($var) { var_dump($var); } // LIB::foo require quot;./ns.phpquot;; /*         <?php                 namespace LIB;                 new foo(); */ __autoload() will be passed namespace name along with class name. autoload will only be triggered if class does not exist in namespace and global scope __autoload() declared inside a namespace will not be called! 7
  • 8. Other NS Syntactic Sugar namespace really::long::pointlessly::verbose::ns;   __NAMESPACE__; // current namespace name        class a{}    get_class(new a()); // really::long::pointlessly::verbose::ns::a use really::long::pointlessly::verbose::ns::a AS b; Reference class from a namespace 8
  • 9. Improved Performance md5() is roughly 10-15% faster Better stack implementation in the engine Constants moved to read-only memory Improve exception handling (simpler & less opcodes) Eliminate open(2) call on (require/include)_once Smaller binary size & startup size with gcc4 Overall Improvement 5-15% 9
  • 11. __DIR__ Introduced __DIR__ magic constant indicating the directory where the script is located. echo dirname(__FILE__); // < PHP 5.3     /* vs */ echo __DIR__; // >= PHP 5.3 11
  • 12. ?: Operator Allows quick retrieval of a non-empty value from 2 values and/or expressions $a = true ?: false; // true $a = false ?: true; // true $a = quot;quot; ?: 1; // 1 $a = 0 ?: 2; // 2 $a = array() ?: array(1); // array(1); $a = strlen(quot;quot;) ?: strlen(quot;aquot;); // 1 12
  • 13. __callStatic() __call() equivalent, but for static methods. class helper {         static function __callStatic($name, $args) {                 echo $name.'('.implode(',', $args).')';         } } helper::test(quot;fooquot;,quot;barquot;); // test(foo,bar) ✴ Dynamic function/method calls are kinda slow... 13
  • 14. Dynamic Static Calls PHP now allows dynamic calls to static methods class helper {         static function foo() { echo __METHOD__; } } $a = quot;helperquot;; $b = quot;fooquot;; $a::$b(); // helper::foo ✴ Dynamic function/method calls are kinda slow... 14
  • 15. Late Static Binding Processing of static events has been extended into execution time from compile time. class A { class A {    public static function whoami() {    public static function whoami() {     echo __CLASS__;       echo __CLASS__;    }    }    public static function identity() {    public static function identity() {      self::whoami();       static::whoami();    }    } } } class B extends A { class B extends A {    public static function whoami() {    public static function whoami() {       echo __CLASS__;       echo __CLASS__;    }    } } } B::identity(); // A <-- PHP < 5.3 B::identity(); // B <-- >= PHP 5.3 ✴ Beware if you use an opcode cache ✴ Not backwards compatible 15
  • 16. MySQLInd Specialized, high speed library to interface with MySQL designed specifically for PHP mysql_fetch_assoc(quot;...quot;); ext/mysql ext/mysql Copy of data in PHP Copy on Write in mysqlind Copy in libmysql Row Data Row Data Row Data Row Data Row Data Row Data MySQL Database 16
  • 17. MySQLInd Better performance Improved memory usage Ability to fetch statistics for performance tuning Built-in driver (no external decencies once again) Many future options due to tight integration with PHP No PDO_MySQL support yet, mysql(i) only for now 17
  • 18. INI Magic Support for “.htaccess” style INI controls for CGI/ FastCGI Per-directory INI settings inside php.ini via [PATH=/var/www/domain.com] not modifiable by the user. Improve error handling Allow use of INI variables and constants from virtually everywhere in the INI files Several other minor improvements 18
  • 19. INI Magic Name for user-defined php.ini (.htaccess) files. Default is quot;.user.iniquot; user_ini.filename = quot;.user.iniquot; To disable this feature set this option to empty value user_ini.filename = TTL for user-defined php.ini files (time-to-live) in seconds. Default is 300 seconds (5 minutes) user_ini.cache_ttl = 300 [PATH=/var/www/domain.com] variables_order = GPC safe_mode = 1 [my variables] somevar = “1234” anothervar = ${somevar} ; anothervar == somevar [ini arrays] foo[bar] = 1 foo[123] = 2 foo[] = 3 19
  • 20. Extra OpenSSL Functions Access to OpenSSL Digest Functions foreach (openssl_get_md_methods() as $d) {// MD4, MD5, SHA512... (12 all in all)   echo $d.quot; - quot;.openssl_digest(quot;fooquot;, quot;md5quot;); //acbd18db4cc2f85cedef654fccc4a4d8 } Access to OpenSSL Cipher Functions // BF-CBC, AES-256 CFB1... (54 all in all) foreach(openssl_get_cipher_methods() as $v) { $val = openssl_encrypt(quot;valuequot;, $v, quot;secretquot;);   openssl_decrypt($val, $v, quot;secretquot;); // value    } Extend openssl_pkey_new() and openssl_pkey_get_details() functions to allow access to internal DSA, RSA and DH keys. The goal was to simply OpenID implementation in PHP 20
  • 21. SPL Improvements Improve nested directory iterations via FilesystemIterator Introduced GlobIterator Various data structure classes: SplDoublyLinkedList, SplStack, SplQueue, SplHeap, SplMinHeap, SplMaxHeap, SplPriorityQueue Several other tongue twister features 21
  • 22. Date Extension Additions Controllable strtotime() via date_create_from_format() $date = strtotime(quot;08-01-07 00:00:00quot;); var_dump(date(quot;Y-m-dquot;, $date)); // string(10) quot;2008-01-07quot; $date = date_create_from_format(quot;m-d-yquot;, quot;08-01-07quot;); var_dump($date->format('Y-m-d')); // string(10) quot;2007-08-01quot; Added date_get_last_errors() that returns errors and warnings in date parsing. array(4) {   [quot;warning_countquot;] => int(0)   [quot;warningsquot;] => array(0) { }   [quot;error_countquot;] => int(2)   [quot;errorsquot;]=>   array(2) {     [2]=> string(40) quot;The separation symbol could not be foundquot;     [6]=> string(13) quot;Trailing dataquot;   } } 22
  • 23. getopt() Improvements Works on Windows Native implementation not dependent on native getopt() implementation. Cross-platform support for longopts (--option) // input: --a=foo --b --c var_dump(getopt(quot;quot;, array(quot;a:quot;,quot;b::quot;,quot;cquot;))); /* output: array(3) {   [quot;aquot;]=>   string(3) quot;fooquot;   [quot;bquot;]=>   bool(false)   [quot;cquot;]=>   bool(false) } */ 23
  • 24. XSLT Profiling Introduction of Xslt Profiling via setProfiling() $xslt = new xsltprocessor();  $xslt->importStylesheet($xml);  $xslt->setProfiling(quot;/tmp/profile.txtquot;);  $xslt->transformToXml($dom); Resulting In: number match name mode Calls Tot 100us Avg 0 date 5 58 11 Total 5 58 24
  • 25. E_DEPRECATED What would a PHP release be without a new error mode? deprecated Used to designate deprecated functionality that maybe, sometime in a far future will get removed, maybe. 25
  • 26. Garbage Collector Memory cleanup for Über-complex and long scripts that need to free-up memory before the end of execution cycle. (!amework folks, this is for you) gc_enable(); // Enable Garbage Collector var_dump(gc_enabled()); // true var_dump(gc_collect_cycles()); // # of elements cleaned up gc_disable(); // Disable Garbage Collector 26
  • 27. NOWDOC A HEREDOC where no escaping is necessary HEREDOC NOWDOC $foo = <<<ONE $bar = <<<‘TWO’ this is $fubar this is $fubar ONE; TWO;      /* string(10) quot;this isquot; */ /* string(16) quot;this is $fubarquot; */ 27
  • 28. Miscellaneous Improvements SQLite Upgraded to 3.5.6 Over 40 bug fixes CGI/FastCGI SAPI Improvements Various stream improvements More things to come ... 28
  • 29. Thank You For Listening Questions? These slides can be found on: http://ilia.ws 29