PHP 5.3/6

38
PHP 5.3/6 Standortbestimmung

description

 

Transcript of PHP 5.3/6

PHP 5.3/6

Standortbestimmung

Thomas Weinert, papaya Software GmbH 2

About me

Application Developer▹ PHP

▹ XSLT/XPath

▹ (some) Javascript papaya CMS

▹ PHP based Content Management System

▹ uses XSLT for Templates

Thomas Weinert, papaya Software GmbH 3

PHP 5.3

„PHP 5.3 is still young“

Thomas Weinert, papaya Software GmbH 4

PHP 5.3

Thomas Weinert, papaya Software GmbH 5

PHP 6

„PHP 6 is already in development“

Thomas Weinert, papaya Software GmbH 6

PHP 6

… for some years ...

Thomas Weinert, papaya Software GmbH 7

PHP 5.3

What do we get?

Thomas Weinert, papaya Software GmbH 8

Bugfixes

Assigned Suspended Feedback NoFeedback

Wont fix Bogus

261 26 45 1651 350 5806

All Closed Open Critical Verified Analyzed

13085 4007(199) 919 (50) 2 11 2

Thomas Weinert, papaya Software GmbH 9

Performance

Performance

about 5 – 15% or more?

Thomas Weinert, papaya Software GmbH 10

Garbage Collection

gc_enable()▹ Activates the circular reference collector

gc_collect_cycles()▹ Forces collection of any existing garbage cycles.

gc_disable() gc_enabled()

Thomas Weinert, papaya Software GmbH 11

PHP.INI

per directory (like .htaccess)▹ Cached

[PATH=/opt/httpd/www.example.com/] [HOST=www.example.com]

Ini „variables“ absolute paths for extensions

Thomas Weinert, papaya Software GmbH 12

Extensions Changed

PCRE, Reflection, SPL▹ can not be disabled any more

MySQL(i)▹ mysqlnd

SQLite▹ SQLite 3 Support

GD▹ removed GD1 and Freetype1 support

Thomas Weinert, papaya Software GmbH 13

Extensions Moved

Moved to PECL▹ fdf

▹ ncurses

▹ sybase

▹ ming

▹ dbase

▹ fbsql

▹ mime_magic

Thomas Weinert, papaya Software GmbH 14

Extensions Added

fileinfo intl phar

Thomas Weinert, papaya Software GmbH 15

Fileinfo

File mimetype▹ from magic bytes

▹ not bullet proof

BC to ext/mime_magic▹ mime_content_type()

Thomas Weinert, papaya Software GmbH 16

Fileinfo Sample

<?php$finfo = finfo_open(FILEINFO_MIME);

foreach (glob("*") as $filename) { echo finfo_file($finfo, $filename) . "\n";}

finfo_close($finfo);?>

Thomas Weinert, papaya Software GmbH 17

INTL

ICU▹ International Components for Unicode

Internationalization▹ String functions

▹ Collator

▹ Number Formatter

▹ Message Formatter

▹ Normalizer

▹ Locale

Thomas Weinert, papaya Software GmbH 18

PHAR

PHP applications in one package easy distribution and installation verify archive integrity PHP stream wrapper tar and zip Phar format with stub<?php include 'phar:///path/to/myphar.phar/file.php';?>

Thomas Weinert, papaya Software GmbH 19

PHAR

Using a stub Makes a PHAR file a PHP script

<?phpPhar::webPhar();__HALT_COMPILER();

http://www.domain.tld/app.phar/page.php

Thomas Weinert, papaya Software GmbH 20

SPL

Now always enabled

many iterators and recursive iterators SPLFixedArray http://www.php.net/spl

Thomas Weinert, papaya Software GmbH 21

Error Reporting

E_DEPRECATED splitted from E_STRICT E_DEPRECATED included in E_ALL

is_a() is not in E_DEPRECATED any more▹ but documentation still says it is

Thomas Weinert, papaya Software GmbH 22

Syntax Sugar

__DIR__ replaces dirname(__FILE__) ?:

▹ $foo = $bar ?: 'default' Nowdoc

▹ $foo = <<<'HTML' // no variables parsed Heredoc

▹ double quotes

▹ static $foo = <<<HTML // no variables allowed

Thomas Weinert, papaya Software GmbH 23

Static

Late Static Binding __callStatic static::foo

Thomas Weinert, papaya Software GmbH 24

LSB - Why

<?phpclass bar { public function show() { var_dump(new self); }}class foo extends bar { public function test() { parent::show(); }}$foo = new foo;$foo->test();?> object(bar)#2 (0) { }

Thomas Weinert, papaya Software GmbH 25

LSB - Why

<?phpclass bar { public function show() { var_dump(new static); }}class foo extends bar { public function test() { parent::show(); }}$foo = new foo;$foo->test();?> object(foo)#2 (0) { }

Thomas Weinert, papaya Software GmbH 26

Dynamic Static Calls

<?phpclass foo { function bar() { var_dump('Hello World'); }}foo::bar();

$o = new foo();$o::bar();

$s = 'foo';$s::bar();?>

Thomas Weinert, papaya Software GmbH 27

Lambda Functions

<?php header('Content-type: text/plain');$text = '<b>Hello <i>World</i></b>';$ptn = '(<(/?)(\w+)([^>]*)>)';

$cb = function($m) { if (strtolower($m[2]) == 'b') { return '<'.$m[1].'strong'.$m[3].'>'; } return '';};echo preg_replace_callback($ptn, $cb, $text);?>

Thomas Weinert, papaya Software GmbH 28

Closures

...$repl = array( 'b' => 'strong', 'i' => 'em');$cb = function ($m) use ($repl) { $tag = strtolower($m[2]); if (!empty($replace[$tag])) { return '<'.$m[1].$repl[$tag].$m[3].'>'; } return '';};echo preg_replace_callback($ptn, $cb, $t);?>

Thomas Weinert, papaya Software GmbH 29

Currying

function curry($callback) { $args = func_get_args(); array_shift($args); return function() use ($callback, $args) { $args = array_merge( func_get_args(), $args ); return call_user_func_array( $callback, $args ); };}

Thomas Weinert, papaya Software GmbH 30

Currying

$cb = curry(array('replace', 'tags'), $replace);echo preg_replace_callback( $pattern, $cb, $text);

class replace { function tags($m, $repl) { $tag = strtolower($m[2]); if (!empty($repl[$tag])) { return '<'.$m[1].$repl[$tag].$m[3].'>'; } return ''; }}

Thomas Weinert, papaya Software GmbH 31

Namespaces

Encapsulation▹ Classes

▹ Functions

▹ Constants __NAMESPACE__ Overload classes

Thomas Weinert, papaya Software GmbH 32

Namespace Separator

::

Old▹ Double Colon

▹ Paamayim Nekudotayim

Current▹ Backslash?

▹ Discussion started

\

Thomas Weinert, papaya Software GmbH 33

Namespaces: Classes

<?php namespace carica::core::strings;const CHARSET = 'utf-8';class escape { public static function forXML($content) { return htmlspecialchars( $content, ENT_QUOTES, CHARSET ); }}?>

Thomas Weinert, papaya Software GmbH 34

Use Namespaces

...namespace carica::frontend;use carica::core::strings as strings;... public function execute() { echo strings::escape::forXML( 'Hello World' ); }...

Thomas Weinert, papaya Software GmbH 35

Namespaces: Constants

PHP-Wiki:▹ constants are case-sensitive, but namespaces are

case-insensitive.

▹ defined() is not aware of namespace aliases.

▹ the namespace part of constants defined with const are lowercased.

Thomas Weinert, papaya Software GmbH 36

GOTO

<?php goto a; print 'Foo'; a: print 'Bar';?>

Thomas Weinert, papaya Software GmbH 37

PHP 6

„Backports“ to PHP 5.3

Upload progress in session Unicode

▹ PHP Source

▹ Functions

▹ Resources

Thomas Weinert, papaya Software GmbH 38

Links

Slides▹ http://www.abasketfulofpapayas.de

PHP 5.3 upgrading notes▹ http://wiki.php.net/doc/scratchpad/upgrade/53

PHP 5.3 ToDo▹ http://wiki.php.net/todo/php53

PHP 6 ToDo▹ http://wiki.php.net/todo/php60