SlideShare ist ein Scribd-Unternehmen logo
1 von 51
Downloaden Sie, um offline zu lesen
KEY FEATRURES
PHP 5.3 - 5.6
FEDERICO LOZADA MOSTO
Twitter: @mostofreddy
Web: mostofreddy.com.ar
Facebook: /mostofreddy
Linkedin: ar.linkedin.com/in/federicolozadamosto
Github: /mostofreddy
History
5.6.0 – 28/08/2014
5.5.0 – 20/06/2013
5.4.0 – 01/03/2012
5.3.0 – 30/07/2009
5.2.0 – 02/11/2006
5.1.0 – 24/11/2005
5.0.0 – 13/07/2004
Fuentes:
✓ http://php.net/eol.php
✓ http://php.net/supported-versions.php
!
PHP 5.3
Namespaces
<?php
namespace mostofreddylogger;
Class Logger {
…
}
?>
<?php
$log = new mostofreddyloggerLogger();
$log->info(“example of namespaces”);
//return example of namespaces
PHP 5.3
Lambdas & Closures
PHP 5.3
$sayHello = function() {
return "Hello world";
};
echo $sayHello();
//return Hello world
$text = "Hello %s";
$sayHello = function($name) use (&$text) {
return sprintf($text, $name);
};
echo $sayHello("phpbsas");
//return Hello phpbsas
PHP 5.4
JSON serializable
PHP 5.4
class Freddy implements JsonSerializable
{
public $data = [];
public function __construct() {
$this->data = array(
'Federico', 'Lozada', 'Mosto'
);
}
public function jsonSerialize() {return $this->data;}
}
echo json_encode(new Freddy());
//return ["Federico","Lozada","Mosto"]
//PHP < 5.4
//{"data":["Federico","Lozada","Mosto"]}
Session handler
PHP < 5.4
$obj = new MySessionHandler;
session_set_save_handler(
array($obj, "open"),
array($obj, "close"),
array($obj, "read"),
array($obj, "write"),
array($obj, "destroy"),
array($obj, "gc")
)
PHP 5.4
class MySessionHandler implements SessionHandlerInterface
{
public function open($savePath, $sessionName) {}
public function close() {}
public function read($id) {}
public function write($id, $data) {}
public function destroy($id) {}
public function gc($maxlifetime) {}
}
$handler = new MySessionHandler();
session_set_save_handler($handler, true);
session_start();
PHP 5.4
function status() {
$status = session_status();
if($status == PHP_SESSION_DISABLED) {
echo "Session is Disabled";
} else if($status == PHP_SESSION_NONE ) {
echo "Session Enabled but No Session values Created";
} else {
echo "Session Enabled and Session values Created";
}
}
status();
//return Session Enabled but No Session values Created
session_start();
status();
//return Session Enabled and Session values Created
Arrays
PHP 5.4
$array = [0, 1, 2, 3, 4];
var_dump($array);
//return
array(6) {
[0]=> int(0)
[1]=> int(1)
[2]=> int(2)
[3]=> int(3)
[4]=> int(4)
}
Short syntax
PHP 5.4Array Deferencing
$txt = "Hello World";
echo explode(" ", $txt)[0];
//return Hello World
function getName() {
return [
'user' => array(
'name'=>'Federico'
)
];
}
echo getName()['user']['name'];
//return Federico
Built-in web server
PHP 5.4
~/www$ php -S localhost:8080
PHP 5.4.0 Development Server started at Mon Apr
2 11:37:48 2012
Listening on localhost:8080
Document root is /var/www
Press Ctrl-C to quit.
PHP 5.4
~/www$ vim server.sh
#! /bin/bash
DOCROOT="/var/www"
HOST=0.0.0.0
PORT=80
ROUTER="/var/www/router.php"
PHP=$(which php)
if [ $? != 0 ] ; then
echo "Unable to find PHP"
exit 1
fi
$PHP -S $HOST:$PORT -t $DOCROOT $ROUTER
Traits
PHP 5.4
trait File {
public function put($m) {error_log($m, 3, '/tmp/log');}
}
trait Log {
use File;
public function addLog($m) {$this->put('LOG: '.$m);}
}
class Test {
use Log;
public function foo() { $this->addLog('test');}
}
$obj = new Test;
$obj->foo();
//return LOG: test
PHP 5.4
trait Game {
public function play() {return "Play Game";}
}
trait Music {
public function play() {return "Play Music";}
}
class Player {
use Game, Music;
}
$o = new Player;
echo $o->play();
Solving confict
PHP does not solve
conflicts automatically
PHP Fatal error: Trait method play has not been applied,
because there are collisions with other trait methods
on Player in /var/www/test/test_traits.php on line 10
PHP 5.4
trait Game {
public function play() {return "Play Game";}
}
trait Music {
public function play() {return "Play Music";}
}
class Player {
use Game, Music {
Game::play as gamePlay;
Music::play insteadof Game;
}
}
$o = new Player;
echo $o->play(); //return Play Music
echo $o->gamePlay(); //return Play Game
PHP 5.5
Generators
PHP < 5.5
function getLines($filename) {
if (!$handler = fopen($filename, 'r')) {
return;
}
$lines = [];
while (false != $line = fgets($handler)) {
$lines[] = $line;
}
fclose($handler);
return $lines;
}
$lines = getLines('file.txt');
foreach ($lines as $line) {
echo $line;
}
PHP 5.5
function getLines($filename) {
if (!$handler = fopen($filename, 'r')) {
return;
}
while (false != $line = fgets($handler)) {
yield $line;
}
fclose($handler);
}
foreach (getLines('file.txt') as $line) {
echo $line;
}
PHP with generators
Total time: 1.3618 seg
Memory: 256 k
PHP classic
Total time: 1.5684 seg
Memory: 2.5 M
PHP 5.5
OPCache
PHP 5.5
PHP 5.5
opcache.enable=1
opcache.enable_cli=1
opcache.memory_consumption=128
opcache.interned_strings_buffer=8
opcache.max_accelerated_files=4000
opcache.revalidate_freq=60
opcache.fast_shutdown=1
Basic configuration
PHP 5.5
Advanced configuration for PHPUnit / Symfony /
Doctrine / Zend / etc
opcache.save_comments=1
opcache.enable_file_override=1
Functions
opcache_reset()
opcache_invalidate($filename, true)
Password Hashing API
PHP 5.5
password_get_info()
password_hash()
password_needs_rehash()
password_verify()
Funtions
PHP 5.5
$hash = password_hash($password, PASSWORD_DEFAULT);
//or
$hash = password_hash(
$password,
PASSWORD_DEFAULT, //default bcrypt
['cost'=>12, 'salt'=> 'asdadlashdoahdlkuagssa']
);
$user->setPass($hash);
$user->save();
PHP 5.5
$hash = $user->getPass();
if (!password_verify($password, $hash) {
throw new Exception('Invalid password');
}
if (password_needs_rehash($hash, PASSWORD_DEFAULT, ['cost' => 18]))
{
$hash = password_hash(
$password, PASSWORD_DEFAULT, ['cost' => 18]
);
$user->setPass($hash);
$user->save();
}
PHP 5.5
var_dump(password_get_info($hash1));
// prints
array(3) {
'algo' => int(1)
'algoName' => string(6) "bcrypt"
'options' => array(1) {
'cost' => int(12)
}
}
PHP 5.6
Variadic functions via …
&&
Argument unpacking via ...
PHP < 5.6
function ides() {
$cant = func_num_args();
echo "Ides count: ".$cant;
}
ides('Eclipse', 'Netbeas');
// Ides count 2
PHP 5.6
function ides($ide, ...$ides) {
echo "Ides count: ".count($ides);
}
ides (
'Eclipse', 'Netbeas', 'Sublime'
);
// Ides count 2
PHP 5.6
function sum(...$numbers) {
$acc = 0;
foreach ($numbers as $n) {
$acc += $n;
}
return $acc;
}
echo sum(1, 2, 3, 4);
// 10
PHP 5.6
function add($a, $b) {
return $a + $b;
}
echo add(...[1, 2]);
// 3
$a = [1, 2];
echo add(...$a);
// 3
PHP 5.6
function showNames($welcome, Person ...$people) {
echo $welcome.PHP_EOL;
foreach ($people as $person) {
echo $person->name.PHP_EOL;
}
}
$a = new Person('Federico');
$b = new Person('Damian');
showNames('Welcome: ', $a, $b);
//Welcome:
//Federico
//Damian
__debugInfo()
PHP 5.6
class C {
private $prop;
public function __construct($val) {
$this->prop = $val;
}
public function __debugInfo() {
return [
'propSquared' => $this->prop ** 2
];
}
}
var_dump(new C(42));
// object(C)#1 (1) {
["propSquared"]=> int(1764)
}
Questions?
FEDERICO LOZADA MOSTO
TW: @mostofreddy
Web: mostofreddy.com.ar
FB: mostofreddy
In: ar.linkedin.com/in/federicolozadamosto
Git: mostofreddy
Thanks!

Weitere ähnliche Inhalte

Was ist angesagt?

Anatomy of a PHP Request ( UTOSC 2010 )
Anatomy of a PHP Request ( UTOSC 2010 )Anatomy of a PHP Request ( UTOSC 2010 )
Anatomy of a PHP Request ( UTOSC 2010 )
Joseph Scott
 
The Php Life Cycle
The Php Life CycleThe Php Life Cycle
The Php Life Cycle
Xinchen Hui
 
GettingStartedWithPHP
GettingStartedWithPHPGettingStartedWithPHP
GettingStartedWithPHP
Nat Weerawan
 
Yapcasia2011 - Hello Embed Perl
Yapcasia2011 - Hello Embed PerlYapcasia2011 - Hello Embed Perl
Yapcasia2011 - Hello Embed Perl
Hideaki Ohno
 
Understanding PHP memory
Understanding PHP memoryUnderstanding PHP memory
Understanding PHP memory
julien pauli
 

Was ist angesagt? (20)

The why and how of moving to PHP 5.5/5.6
The why and how of moving to PHP 5.5/5.6The why and how of moving to PHP 5.5/5.6
The why and how of moving to PHP 5.5/5.6
 
Quick tour of PHP from inside
Quick tour of PHP from insideQuick tour of PHP from inside
Quick tour of PHP from inside
 
Php 7 hhvm and co
Php 7 hhvm and coPhp 7 hhvm and co
Php 7 hhvm and co
 
PHP7 Presentation
PHP7 PresentationPHP7 Presentation
PHP7 Presentation
 
Introduction to PHP
Introduction to PHPIntroduction to PHP
Introduction to PHP
 
Anatomy of a PHP Request ( UTOSC 2010 )
Anatomy of a PHP Request ( UTOSC 2010 )Anatomy of a PHP Request ( UTOSC 2010 )
Anatomy of a PHP Request ( UTOSC 2010 )
 
PHP7 is coming
PHP7 is comingPHP7 is coming
PHP7 is coming
 
The Php Life Cycle
The Php Life CycleThe Php Life Cycle
The Php Life Cycle
 
Introduction to PHP - Basics of PHP
Introduction to PHP - Basics of PHPIntroduction to PHP - Basics of PHP
Introduction to PHP - Basics of PHP
 
Mysqlnd, an unknown powerful PHP extension
Mysqlnd, an unknown powerful PHP extensionMysqlnd, an unknown powerful PHP extension
Mysqlnd, an unknown powerful PHP extension
 
GettingStartedWithPHP
GettingStartedWithPHPGettingStartedWithPHP
GettingStartedWithPHP
 
A new way to develop with WordPress!
A new way to develop with WordPress!A new way to develop with WordPress!
A new way to develop with WordPress!
 
10 Most Important Features of New PHP 5.6
10 Most Important Features of New PHP 5.610 Most Important Features of New PHP 5.6
10 Most Important Features of New PHP 5.6
 
Yapcasia2011 - Hello Embed Perl
Yapcasia2011 - Hello Embed PerlYapcasia2011 - Hello Embed Perl
Yapcasia2011 - Hello Embed Perl
 
Php.ppt
Php.pptPhp.ppt
Php.ppt
 
New Features in PHP 5.3
New Features in PHP 5.3New Features in PHP 5.3
New Features in PHP 5.3
 
Web Apps in Perl - HTTP 101
Web Apps in Perl - HTTP 101Web Apps in Perl - HTTP 101
Web Apps in Perl - HTTP 101
 
Understanding PHP memory
Understanding PHP memoryUnderstanding PHP memory
Understanding PHP memory
 
Modern PHP
Modern PHPModern PHP
Modern PHP
 
Profiling php5 to php7
Profiling php5 to php7Profiling php5 to php7
Profiling php5 to php7
 

Ähnlich wie Key features PHP 5.3 - 5.6

HackU PHP and Node.js
HackU PHP and Node.jsHackU PHP and Node.js
HackU PHP and Node.js
souridatta
 

Ähnlich wie Key features PHP 5.3 - 5.6 (20)

The new features of PHP 7 - Enrico Zimuel - Codemotion Milan 2016
The new features of PHP 7 - Enrico Zimuel - Codemotion Milan 2016The new features of PHP 7 - Enrico Zimuel - Codemotion Milan 2016
The new features of PHP 7 - Enrico Zimuel - Codemotion Milan 2016
 
PHP Without PHP—Confoo
PHP Without PHP—ConfooPHP Without PHP—Confoo
PHP Without PHP—Confoo
 
ZendCon 08 php 5.3
ZendCon 08 php 5.3ZendCon 08 php 5.3
ZendCon 08 php 5.3
 
Php mysql ppt
Php mysql pptPhp mysql ppt
Php mysql ppt
 
The why and how of moving to php 5.4/5.5
The why and how of moving to php 5.4/5.5The why and how of moving to php 5.4/5.5
The why and how of moving to php 5.4/5.5
 
Php 7 compliance workshop singapore
Php 7 compliance workshop singaporePhp 7 compliance workshop singapore
Php 7 compliance workshop singapore
 
Php with my sql
Php with my sqlPhp with my sql
Php with my sql
 
basic concept of php(Gunikhan sonowal)
basic concept of php(Gunikhan sonowal)basic concept of php(Gunikhan sonowal)
basic concept of php(Gunikhan sonowal)
 
Php tutorial
Php tutorialPhp tutorial
Php tutorial
 
What's new with PHP7
What's new with PHP7What's new with PHP7
What's new with PHP7
 
Php Tutorial
Php TutorialPhp Tutorial
Php Tutorial
 
Introducation to php for beginners
Introducation to php for beginners Introducation to php for beginners
Introducation to php for beginners
 
HackU PHP and Node.js
HackU PHP and Node.jsHackU PHP and Node.js
HackU PHP and Node.js
 
An introduction to PHP 5.4
An introduction to PHP 5.4An introduction to PHP 5.4
An introduction to PHP 5.4
 
Apache and PHP: Why httpd.conf is your new BFF!
Apache and PHP: Why httpd.conf is your new BFF!Apache and PHP: Why httpd.conf is your new BFF!
Apache and PHP: Why httpd.conf is your new BFF!
 
関西PHP勉強会 php5.4つまみぐい
関西PHP勉強会 php5.4つまみぐい関西PHP勉強会 php5.4つまみぐい
関西PHP勉強会 php5.4つまみぐい
 
Debugging: Rules & Tools
Debugging: Rules & ToolsDebugging: Rules & Tools
Debugging: Rules & Tools
 
PHP Basics and Demo HackU
PHP Basics and Demo HackUPHP Basics and Demo HackU
PHP Basics and Demo HackU
 
Die .htaccess richtig nutzen
Die .htaccess richtig nutzenDie .htaccess richtig nutzen
Die .htaccess richtig nutzen
 
PHP File Handling
PHP File Handling PHP File Handling
PHP File Handling
 

Mehr von Federico Damián Lozada Mosto

Travis-CI - Continuos integration in the cloud for PHP
Travis-CI - Continuos integration in the cloud for PHPTravis-CI - Continuos integration in the cloud for PHP
Travis-CI - Continuos integration in the cloud for PHP
Federico Damián Lozada Mosto
 

Mehr von Federico Damián Lozada Mosto (8)

Php 5.6
Php 5.6Php 5.6
Php 5.6
 
Solid Principles & Design patterns with PHP examples
Solid Principles & Design patterns with PHP examplesSolid Principles & Design patterns with PHP examples
Solid Principles & Design patterns with PHP examples
 
Implementando una Arquitectura de Microservicios
Implementando una Arquitectura de MicroserviciosImplementando una Arquitectura de Microservicios
Implementando una Arquitectura de Microservicios
 
Composer
ComposerComposer
Composer
 
Travis-CI - Continuos integration in the cloud for PHP
Travis-CI - Continuos integration in the cloud for PHPTravis-CI - Continuos integration in the cloud for PHP
Travis-CI - Continuos integration in the cloud for PHP
 
Introduction to unit testing
Introduction to unit testingIntroduction to unit testing
Introduction to unit testing
 
PHP 5.4
PHP 5.4PHP 5.4
PHP 5.4
 
Scrum
ScrumScrum
Scrum
 

Kürzlich hochgeladen

CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female serviceCALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
anilsa9823
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
mohitmore19
 

Kürzlich hochgeladen (20)

CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female serviceCALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.js
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial Goals
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptx
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docx
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
 
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS LiveVip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Models
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.com
 

Key features PHP 5.3 - 5.6

  • 2. FEDERICO LOZADA MOSTO Twitter: @mostofreddy Web: mostofreddy.com.ar Facebook: /mostofreddy Linkedin: ar.linkedin.com/in/federicolozadamosto Github: /mostofreddy
  • 4. 5.6.0 – 28/08/2014 5.5.0 – 20/06/2013 5.4.0 – 01/03/2012 5.3.0 – 30/07/2009 5.2.0 – 02/11/2006 5.1.0 – 24/11/2005 5.0.0 – 13/07/2004 Fuentes: ✓ http://php.net/eol.php ✓ http://php.net/supported-versions.php !
  • 7. <?php namespace mostofreddylogger; Class Logger { … } ?> <?php $log = new mostofreddyloggerLogger(); $log->info(“example of namespaces”); //return example of namespaces PHP 5.3
  • 9. PHP 5.3 $sayHello = function() { return "Hello world"; }; echo $sayHello(); //return Hello world $text = "Hello %s"; $sayHello = function($name) use (&$text) { return sprintf($text, $name); }; echo $sayHello("phpbsas"); //return Hello phpbsas
  • 12. PHP 5.4 class Freddy implements JsonSerializable { public $data = []; public function __construct() { $this->data = array( 'Federico', 'Lozada', 'Mosto' ); } public function jsonSerialize() {return $this->data;} } echo json_encode(new Freddy()); //return ["Federico","Lozada","Mosto"] //PHP < 5.4 //{"data":["Federico","Lozada","Mosto"]}
  • 14. PHP < 5.4 $obj = new MySessionHandler; session_set_save_handler( array($obj, "open"), array($obj, "close"), array($obj, "read"), array($obj, "write"), array($obj, "destroy"), array($obj, "gc") )
  • 15. PHP 5.4 class MySessionHandler implements SessionHandlerInterface { public function open($savePath, $sessionName) {} public function close() {} public function read($id) {} public function write($id, $data) {} public function destroy($id) {} public function gc($maxlifetime) {} } $handler = new MySessionHandler(); session_set_save_handler($handler, true); session_start();
  • 16. PHP 5.4 function status() { $status = session_status(); if($status == PHP_SESSION_DISABLED) { echo "Session is Disabled"; } else if($status == PHP_SESSION_NONE ) { echo "Session Enabled but No Session values Created"; } else { echo "Session Enabled and Session values Created"; } } status(); //return Session Enabled but No Session values Created session_start(); status(); //return Session Enabled and Session values Created
  • 18. PHP 5.4 $array = [0, 1, 2, 3, 4]; var_dump($array); //return array(6) { [0]=> int(0) [1]=> int(1) [2]=> int(2) [3]=> int(3) [4]=> int(4) } Short syntax
  • 19. PHP 5.4Array Deferencing $txt = "Hello World"; echo explode(" ", $txt)[0]; //return Hello World function getName() { return [ 'user' => array( 'name'=>'Federico' ) ]; } echo getName()['user']['name']; //return Federico
  • 21. PHP 5.4 ~/www$ php -S localhost:8080 PHP 5.4.0 Development Server started at Mon Apr 2 11:37:48 2012 Listening on localhost:8080 Document root is /var/www Press Ctrl-C to quit.
  • 22. PHP 5.4 ~/www$ vim server.sh #! /bin/bash DOCROOT="/var/www" HOST=0.0.0.0 PORT=80 ROUTER="/var/www/router.php" PHP=$(which php) if [ $? != 0 ] ; then echo "Unable to find PHP" exit 1 fi $PHP -S $HOST:$PORT -t $DOCROOT $ROUTER
  • 24. PHP 5.4 trait File { public function put($m) {error_log($m, 3, '/tmp/log');} } trait Log { use File; public function addLog($m) {$this->put('LOG: '.$m);} } class Test { use Log; public function foo() { $this->addLog('test');} } $obj = new Test; $obj->foo(); //return LOG: test
  • 25. PHP 5.4 trait Game { public function play() {return "Play Game";} } trait Music { public function play() {return "Play Music";} } class Player { use Game, Music; } $o = new Player; echo $o->play(); Solving confict PHP does not solve conflicts automatically PHP Fatal error: Trait method play has not been applied, because there are collisions with other trait methods on Player in /var/www/test/test_traits.php on line 10
  • 26. PHP 5.4 trait Game { public function play() {return "Play Game";} } trait Music { public function play() {return "Play Music";} } class Player { use Game, Music { Game::play as gamePlay; Music::play insteadof Game; } } $o = new Player; echo $o->play(); //return Play Music echo $o->gamePlay(); //return Play Game
  • 29. PHP < 5.5 function getLines($filename) { if (!$handler = fopen($filename, 'r')) { return; } $lines = []; while (false != $line = fgets($handler)) { $lines[] = $line; } fclose($handler); return $lines; } $lines = getLines('file.txt'); foreach ($lines as $line) { echo $line; }
  • 30. PHP 5.5 function getLines($filename) { if (!$handler = fopen($filename, 'r')) { return; } while (false != $line = fgets($handler)) { yield $line; } fclose($handler); } foreach (getLines('file.txt') as $line) { echo $line; }
  • 31. PHP with generators Total time: 1.3618 seg Memory: 256 k PHP classic Total time: 1.5684 seg Memory: 2.5 M PHP 5.5
  • 35. PHP 5.5 Advanced configuration for PHPUnit / Symfony / Doctrine / Zend / etc opcache.save_comments=1 opcache.enable_file_override=1 Functions opcache_reset() opcache_invalidate($filename, true)
  • 38. PHP 5.5 $hash = password_hash($password, PASSWORD_DEFAULT); //or $hash = password_hash( $password, PASSWORD_DEFAULT, //default bcrypt ['cost'=>12, 'salt'=> 'asdadlashdoahdlkuagssa'] ); $user->setPass($hash); $user->save();
  • 39. PHP 5.5 $hash = $user->getPass(); if (!password_verify($password, $hash) { throw new Exception('Invalid password'); } if (password_needs_rehash($hash, PASSWORD_DEFAULT, ['cost' => 18])) { $hash = password_hash( $password, PASSWORD_DEFAULT, ['cost' => 18] ); $user->setPass($hash); $user->save(); }
  • 40. PHP 5.5 var_dump(password_get_info($hash1)); // prints array(3) { 'algo' => int(1) 'algoName' => string(6) "bcrypt" 'options' => array(1) { 'cost' => int(12) } }
  • 42. Variadic functions via … && Argument unpacking via ...
  • 43. PHP < 5.6 function ides() { $cant = func_num_args(); echo "Ides count: ".$cant; } ides('Eclipse', 'Netbeas'); // Ides count 2
  • 44. PHP 5.6 function ides($ide, ...$ides) { echo "Ides count: ".count($ides); } ides ( 'Eclipse', 'Netbeas', 'Sublime' ); // Ides count 2
  • 45. PHP 5.6 function sum(...$numbers) { $acc = 0; foreach ($numbers as $n) { $acc += $n; } return $acc; } echo sum(1, 2, 3, 4); // 10
  • 46. PHP 5.6 function add($a, $b) { return $a + $b; } echo add(...[1, 2]); // 3 $a = [1, 2]; echo add(...$a); // 3
  • 47. PHP 5.6 function showNames($welcome, Person ...$people) { echo $welcome.PHP_EOL; foreach ($people as $person) { echo $person->name.PHP_EOL; } } $a = new Person('Federico'); $b = new Person('Damian'); showNames('Welcome: ', $a, $b); //Welcome: //Federico //Damian
  • 49. PHP 5.6 class C { private $prop; public function __construct($val) { $this->prop = $val; } public function __debugInfo() { return [ 'propSquared' => $this->prop ** 2 ]; } } var_dump(new C(42)); // object(C)#1 (1) { ["propSquared"]=> int(1764) }
  • 51. FEDERICO LOZADA MOSTO TW: @mostofreddy Web: mostofreddy.com.ar FB: mostofreddy In: ar.linkedin.com/in/federicolozadamosto Git: mostofreddy Thanks!