SlideShare a Scribd company logo
PHP 5.4 New Features
LifeMichael.com
Haim Michael
October 14th, 2012
All logos, trade marks and brand names used in this presentation belong
to the respective owners.
Table of Content
LifeMichael.com
● Support for Traits
● Arrays Short Syntax
● Function Array Dereferencing
● PHP Short Tags
● Instantiation Member Access
● Binary Number Format
● Session Upload Process
● Development Web Server
Support for Traits
LifeMichael.com
● PHP 5.4 we can define Traits. Defining a trait is very
similar to defining a class. Instead of using the keyword
class we use the keyword trait.
● The purpose of traits is to group functionality in a fine
grained and consistent way.
● It is not possible to instantiate a trait. The trait servers as
an additional capability when using inheritance in our
code.
Support for Traits
LifeMichael.com
<?php
trait Academic
{
function think()
{
echo "i m thinking!";
}
}
Support for Traits
LifeMichael.com
class Person
{
private $id;
private $name;
function __construct($idValue,$nameValue)
{
$this->id = $idValue;
$this->name = $nameValue;
}
function __toString()
{
return "id=".$this->id." name=".$this->name;
}
}
Support for Traits
LifeMichael.com
class Student extends Person
{
use Academic;
private $avg;
function __construct($idVal,$nameVal,$avgVal)
{
parent::__construct($idVal,$nameVal);
$this->avg = $avgVal;
}
function __toString()
{
$str = parent::__toString();
return "avg=".$this->avg.$str;
}
}
Support for Traits
LifeMichael.com
class Lecturer extends Person
{
use Academic;
private $degree;
function __construct($idVal,$nameVal,$degreeVal)
{
parent::__construct($idVal,$nameVal);
$this->degree = $degreeVal;
}
function __toString()
{
$str = parent::__toString();
return "degree=".$this->degree.$str;
}
}
Support for Traits
LifeMichael.com
$student = new Student(123123,"mosh",98);
$lecturer = new Lecturer(42343,"dan","mba");
$student->think();
echo "<hr/>";
$lecturer->think();
?>
Support for Traits
LifeMichael.com
● Methods of the current class override methods we
inserted using the trait.
● Methods inserted by a trait override methods inherited
from a base class.
● We can insert multiple traits into one class by listing them
in the use statement separated by commas.
● If two traits (or more) insert two (or more) methods with
the same name then a fatal error is produced.
Support for Traits
LifeMichael.com
● We can use the insteadof operator in order to choose
the exact method we want to use.
● We can use the as operator in order to include a
conflicting method under another name.
Support for Traits
LifeMichael.com
<?php
trait Player
{
function play()
{
echo "<h1>whoo-a</h1>";
}
function printdetails()
{
echo "<h1>player...</h1>";
}
}
trait Gamer
{
function play()
{
echo "<h1>shoooo</h1>";
}
function printdetails()
{
echo "<h1>gamer...</h1>";
}
}
Support for Traits
LifeMichael.com
class Person
{
use Gamer, Player
{
Gamer::printdetails insteadof Player;
Player::play insteadof Gamer;
Gamer::play as xplay;
}
}
$ob = new Person();
$ob->xplay();
$ob->play();
$ob->printdetails();
?>
Support for Traits
LifeMichael.com
● We can define a trait composed of others. Doing so we
can put together separated traits into one.
trait Gamer
{
function play()
{
echo "play...";
}
}
trait Gambler
{
function gamble()
{
echo "gamble...";
}
}
Support for Traits
LifeMichael.com
trait GamblingGamer
{
use Gambler, Gamer;
}
class User
{
use GamblingGamer;
}
$ob = new User();
$ob->gamble();
$ob->play();
?>
Support for Traits
LifeMichael.com
● We can define a trait that includes the definition for
abstract methods. Doing so, we can use that trait to
impose requirements upon the classes that use it.
● It is possible to define our trait with properties. When
instantiating a class that uses our trait we will be able to
refer those properties in the new created object. If the
class that uses our trait includes the definition for a
property with the same name we will get an error.
Arrays Short Syntax
LifeMichael.com
● As of PHP 5.4 we can create new arrays in the following
new short syntax:
<?php
$vec_b = ['a'=>'australia','b'=>'belgium','c'=>'canada'];
foreach($vec_b as $k=>$v)
{
echo " ".$k."=>".$v;
}
?>
Function Array Dereferncing
LifeMichael.com
● As of PHP 5.4 we can develop a function that returns an
array and use a call to that function as if it was an array.
<?php
function countries()
{
$vec = [“italy”,”france”,”israel”];
return $vec;
}
echo countries()[0];
?>
PHP Short Tags
LifeMichael.com
●
PHP 5.4 supports the <?…?> and <?= expression ?> short
tags by default. We don't need to introduce any change in
php.ini in order to use them.
<?
$numA = 24;
$numB = 4;
?>
<h1><?=($numA+$numB)?></h1>
Instantiation Member Access
LifeMichael.com
● PHP 5.4 allows us to access class members on the
object instantiation. It is useful in those cases when we
need to access a single member of an object and don't
need the object.
<?
class Utils
{
function calc($numA,$numB)
{
return $numA+$numB;
}
}
$temp = (new Utils())->calc(3,4);
echo $temp;
?>
Binary Number Format
LifeMichael.com
● PHP 5.4 allows us to write binary numbers. We just
need to precede our number with 0b.
<?
$a = 0b101;
$b = 0b110;
$c = $a + $b;
echo $c; // 11
?>
Session Upload Process
LifeMichael.com
● PHP 5.4 allows us to get detailed information about the
files that are currently been uploaded.
The form might be looking like this.
<?php
$key = ini_get("session.upload_progress.prefix").
$_POST[ini_get("session.upload_progress.name")];
var_dump($_SESSION[$key]);
?>
<form action="upload.php" method="POST" enctype="multipart/form-data">
<input type="hidden"
name="<?php echo ini_get("session.upload_progress.name"); ?>"
value="123" />
<input type="file" name="file1" />
<input type="file" name="file2" />
<input type="file" name="file3" />
<input type="submit" />
</form>
Development Web Server
LifeMichael.com
● PHP 5.4 includes a built-in web server. This server
might assist during the development phase.
Questions & Answers
LifeMichael.com
● Two courses you might find interesting include
PHP Cross Platform Mobile Applications
more info
.NET Cloud Based Web Applications
more info
Android 4.1 Applications Development
more info
● If you enjoyed my lecture please leave me a comment
at http://speakermix.com/life-michael.
Thanks for your time!
Haim.

More Related Content

What's hot

Php pattern matching
Php pattern matchingPhp pattern matching
Php pattern matchingJIGAR MAKHIJA
 
Introduction To Php For Wit2009
Introduction To Php For Wit2009Introduction To Php For Wit2009
Introduction To Php For Wit2009cwarren
 
Php7 HHVM and co
Php7 HHVM and coPhp7 HHVM and co
Php7 HHVM and coweltling
 
Arrays &amp; functions in php
Arrays &amp; functions in phpArrays &amp; functions in php
Arrays &amp; functions in phpAshish Chamoli
 
Class 3 - PHP Functions
Class 3 - PHP FunctionsClass 3 - PHP Functions
Class 3 - PHP FunctionsAhmed Swilam
 
Just-In-Time Compiler in PHP 8
Just-In-Time Compiler in PHP 8Just-In-Time Compiler in PHP 8
Just-In-Time Compiler in PHP 8Nikita Popov
 
Driving Design with PhpSpec
Driving Design with PhpSpecDriving Design with PhpSpec
Driving Design with PhpSpecCiaranMcNulty
 
Class 8 - Database Programming
Class 8 - Database ProgrammingClass 8 - Database Programming
Class 8 - Database ProgrammingAhmed Swilam
 
Zend Certification PHP 5 Sample Questions
Zend Certification PHP 5 Sample QuestionsZend Certification PHP 5 Sample Questions
Zend Certification PHP 5 Sample QuestionsJagat Kothari
 
Php server variables
Php server variablesPhp server variables
Php server variablesJIGAR MAKHIJA
 
07 Introduction to PHP #burningkeyboards
07 Introduction to PHP #burningkeyboards07 Introduction to PHP #burningkeyboards
07 Introduction to PHP #burningkeyboardsDenis Ristic
 
Nikita Popov "What’s new in PHP 8.0?"
Nikita Popov "What’s new in PHP 8.0?"Nikita Popov "What’s new in PHP 8.0?"
Nikita Popov "What’s new in PHP 8.0?"Fwdays
 

What's hot (20)

Php pattern matching
Php pattern matchingPhp pattern matching
Php pattern matching
 
PHP FUNCTIONS
PHP FUNCTIONSPHP FUNCTIONS
PHP FUNCTIONS
 
Introduction to php php++
Introduction to php php++Introduction to php php++
Introduction to php php++
 
Introduction To Php For Wit2009
Introduction To Php For Wit2009Introduction To Php For Wit2009
Introduction To Php For Wit2009
 
Php7 HHVM and co
Php7 HHVM and coPhp7 HHVM and co
Php7 HHVM and co
 
Arrays &amp; functions in php
Arrays &amp; functions in phpArrays &amp; functions in php
Arrays &amp; functions in php
 
Class 3 - PHP Functions
Class 3 - PHP FunctionsClass 3 - PHP Functions
Class 3 - PHP Functions
 
Introduction to php basics
Introduction to php   basicsIntroduction to php   basics
Introduction to php basics
 
Just-In-Time Compiler in PHP 8
Just-In-Time Compiler in PHP 8Just-In-Time Compiler in PHP 8
Just-In-Time Compiler in PHP 8
 
4.2 PHP Function
4.2 PHP Function4.2 PHP Function
4.2 PHP Function
 
Data Types In PHP
Data Types In PHPData Types In PHP
Data Types In PHP
 
Driving Design with PhpSpec
Driving Design with PhpSpecDriving Design with PhpSpec
Driving Design with PhpSpec
 
Introduction to PHP
Introduction to PHPIntroduction to PHP
Introduction to PHP
 
Class 8 - Database Programming
Class 8 - Database ProgrammingClass 8 - Database Programming
Class 8 - Database Programming
 
Zend Certification PHP 5 Sample Questions
Zend Certification PHP 5 Sample QuestionsZend Certification PHP 5 Sample Questions
Zend Certification PHP 5 Sample Questions
 
Php server variables
Php server variablesPhp server variables
Php server variables
 
07 Introduction to PHP #burningkeyboards
07 Introduction to PHP #burningkeyboards07 Introduction to PHP #burningkeyboards
07 Introduction to PHP #burningkeyboards
 
Functions in PHP
Functions in PHPFunctions in PHP
Functions in PHP
 
Introduction in php
Introduction in phpIntroduction in php
Introduction in php
 
Nikita Popov "What’s new in PHP 8.0?"
Nikita Popov "What’s new in PHP 8.0?"Nikita Popov "What’s new in PHP 8.0?"
Nikita Popov "What’s new in PHP 8.0?"
 

Similar to PHP 5.4 New Features

Lecture2_IntroductionToPHP_Spring2023.pdf
Lecture2_IntroductionToPHP_Spring2023.pdfLecture2_IntroductionToPHP_Spring2023.pdf
Lecture2_IntroductionToPHP_Spring2023.pdfShaimaaMohamedGalal
 
Php7 傳說中的第七隻大象
Php7 傳說中的第七隻大象Php7 傳說中的第七隻大象
Php7 傳說中的第七隻大象bobo52310
 
Php7 hhvm and co
Php7 hhvm and coPhp7 hhvm and co
Php7 hhvm and coPierre Joye
 
PHP Interview Questions-ppt
PHP Interview Questions-pptPHP Interview Questions-ppt
PHP Interview Questions-pptMayank Kumar
 
PHP-03-Functions.ppt
PHP-03-Functions.pptPHP-03-Functions.ppt
PHP-03-Functions.pptJamers2
 
PHP complete reference with database concepts for beginners
PHP complete reference with database concepts for beginnersPHP complete reference with database concepts for beginners
PHP complete reference with database concepts for beginnersMohammed Mushtaq Ahmed
 
What's new in PHP 8.0?
What's new in PHP 8.0?What's new in PHP 8.0?
What's new in PHP 8.0?Nikita Popov
 
Introduction to PHP - Basics of PHP
Introduction to PHP - Basics of PHPIntroduction to PHP - Basics of PHP
Introduction to PHP - Basics of PHPwahidullah mudaser
 
Simplify your professional web development with symfony
Simplify your professional web development with symfonySimplify your professional web development with symfony
Simplify your professional web development with symfonyFrancois Zaninotto
 
Various Ways of Using WordPress
Various Ways of Using WordPressVarious Ways of Using WordPress
Various Ways of Using WordPressNick La
 
関西PHP勉強会 php5.4つまみぐい
関西PHP勉強会 php5.4つまみぐい関西PHP勉強会 php5.4つまみぐい
関西PHP勉強会 php5.4つまみぐいHisateru Tanaka
 
PHP Arrays - indexed and associative array.
PHP Arrays - indexed and associative array. PHP Arrays - indexed and associative array.
PHP Arrays - indexed and associative array. wahidullah mudaser
 
Living With Legacy Code
Living With Legacy CodeLiving With Legacy Code
Living With Legacy CodeRowan Merewood
 
Getting started with php
Getting started with phpGetting started with php
Getting started with phpJoe Ferguson
 
Hsc IT 5. Server-Side Scripting (PHP).pdf
Hsc IT 5. Server-Side Scripting (PHP).pdfHsc IT 5. Server-Side Scripting (PHP).pdf
Hsc IT 5. Server-Side Scripting (PHP).pdfAAFREEN SHAIKH
 

Similar to PHP 5.4 New Features (20)

Lecture2_IntroductionToPHP_Spring2023.pdf
Lecture2_IntroductionToPHP_Spring2023.pdfLecture2_IntroductionToPHP_Spring2023.pdf
Lecture2_IntroductionToPHP_Spring2023.pdf
 
Php7 傳說中的第七隻大象
Php7 傳說中的第七隻大象Php7 傳說中的第七隻大象
Php7 傳說中的第七隻大象
 
Php7 hhvm and co
Php7 hhvm and coPhp7 hhvm and co
Php7 hhvm and co
 
PHP Interview Questions-ppt
PHP Interview Questions-pptPHP Interview Questions-ppt
PHP Interview Questions-ppt
 
PHP-03-Functions.ppt
PHP-03-Functions.pptPHP-03-Functions.ppt
PHP-03-Functions.ppt
 
PHP-03-Functions.ppt
PHP-03-Functions.pptPHP-03-Functions.ppt
PHP-03-Functions.ppt
 
PHP complete reference with database concepts for beginners
PHP complete reference with database concepts for beginnersPHP complete reference with database concepts for beginners
PHP complete reference with database concepts for beginners
 
What's new in PHP 8.0?
What's new in PHP 8.0?What's new in PHP 8.0?
What's new in PHP 8.0?
 
Introduction to PHP - Basics of PHP
Introduction to PHP - Basics of PHPIntroduction to PHP - Basics of PHP
Introduction to PHP - Basics of PHP
 
Introduction to php
Introduction to phpIntroduction to php
Introduction to php
 
Php tutorial
Php tutorialPhp tutorial
Php tutorial
 
Simplify your professional web development with symfony
Simplify your professional web development with symfonySimplify your professional web development with symfony
Simplify your professional web development with symfony
 
Various Ways of Using WordPress
Various Ways of Using WordPressVarious Ways of Using WordPress
Various Ways of Using WordPress
 
関西PHP勉強会 php5.4つまみぐい
関西PHP勉強会 php5.4つまみぐい関西PHP勉強会 php5.4つまみぐい
関西PHP勉強会 php5.4つまみぐい
 
Day1
Day1Day1
Day1
 
Hacking with hhvm
Hacking with hhvmHacking with hhvm
Hacking with hhvm
 
PHP Arrays - indexed and associative array.
PHP Arrays - indexed and associative array. PHP Arrays - indexed and associative array.
PHP Arrays - indexed and associative array.
 
Living With Legacy Code
Living With Legacy CodeLiving With Legacy Code
Living With Legacy Code
 
Getting started with php
Getting started with phpGetting started with php
Getting started with php
 
Hsc IT 5. Server-Side Scripting (PHP).pdf
Hsc IT 5. Server-Side Scripting (PHP).pdfHsc IT 5. Server-Side Scripting (PHP).pdf
Hsc IT 5. Server-Side Scripting (PHP).pdf
 

More from Haim Michael

Virtual Threads in Java
Virtual Threads in JavaVirtual Threads in Java
Virtual Threads in JavaHaim Michael
 
MongoDB Design Patterns
MongoDB Design PatternsMongoDB Design Patterns
MongoDB Design PatternsHaim Michael
 
Introduction to SQL Injections
Introduction to SQL InjectionsIntroduction to SQL Injections
Introduction to SQL InjectionsHaim Michael
 
Record Classes in Java
Record Classes in JavaRecord Classes in Java
Record Classes in JavaHaim Michael
 
Microservices Design Patterns
Microservices Design PatternsMicroservices Design Patterns
Microservices Design PatternsHaim Michael
 
Structural Pattern Matching in Python
Structural Pattern Matching in PythonStructural Pattern Matching in Python
Structural Pattern Matching in PythonHaim Michael
 
Unit Testing in Python
Unit Testing in PythonUnit Testing in Python
Unit Testing in PythonHaim Michael
 
OOP Best Practices in JavaScript
OOP Best Practices in JavaScriptOOP Best Practices in JavaScript
OOP Best Practices in JavaScriptHaim Michael
 
JavaScript Jump Start 20220214
JavaScript Jump Start 20220214JavaScript Jump Start 20220214
JavaScript Jump Start 20220214Haim Michael
 
Bootstrap Jump Start
Bootstrap Jump StartBootstrap Jump Start
Bootstrap Jump StartHaim Michael
 
What is new in PHP
What is new in PHPWhat is new in PHP
What is new in PHPHaim Michael
 
What is new in Python 3.9
What is new in Python 3.9What is new in Python 3.9
What is new in Python 3.9Haim Michael
 
Programming in Python on Steroid
Programming in Python on SteroidProgramming in Python on Steroid
Programming in Python on SteroidHaim Michael
 
The matplotlib Library
The matplotlib LibraryThe matplotlib Library
The matplotlib LibraryHaim Michael
 
Pandas meetup 20200908
Pandas meetup 20200908Pandas meetup 20200908
Pandas meetup 20200908Haim Michael
 
The num py_library_20200818
The num py_library_20200818The num py_library_20200818
The num py_library_20200818Haim Michael
 
Jupyter notebook 20200728
Jupyter notebook 20200728Jupyter notebook 20200728
Jupyter notebook 20200728Haim Michael
 
Node.js Crash Course (Jump Start)
Node.js Crash Course (Jump Start) Node.js Crash Course (Jump Start)
Node.js Crash Course (Jump Start) Haim Michael
 

More from Haim Michael (20)

Anti Patterns
Anti PatternsAnti Patterns
Anti Patterns
 
Virtual Threads in Java
Virtual Threads in JavaVirtual Threads in Java
Virtual Threads in Java
 
MongoDB Design Patterns
MongoDB Design PatternsMongoDB Design Patterns
MongoDB Design Patterns
 
Introduction to SQL Injections
Introduction to SQL InjectionsIntroduction to SQL Injections
Introduction to SQL Injections
 
Record Classes in Java
Record Classes in JavaRecord Classes in Java
Record Classes in Java
 
Microservices Design Patterns
Microservices Design PatternsMicroservices Design Patterns
Microservices Design Patterns
 
Structural Pattern Matching in Python
Structural Pattern Matching in PythonStructural Pattern Matching in Python
Structural Pattern Matching in Python
 
Unit Testing in Python
Unit Testing in PythonUnit Testing in Python
Unit Testing in Python
 
OOP Best Practices in JavaScript
OOP Best Practices in JavaScriptOOP Best Practices in JavaScript
OOP Best Practices in JavaScript
 
Java Jump Start
Java Jump StartJava Jump Start
Java Jump Start
 
JavaScript Jump Start 20220214
JavaScript Jump Start 20220214JavaScript Jump Start 20220214
JavaScript Jump Start 20220214
 
Bootstrap Jump Start
Bootstrap Jump StartBootstrap Jump Start
Bootstrap Jump Start
 
What is new in PHP
What is new in PHPWhat is new in PHP
What is new in PHP
 
What is new in Python 3.9
What is new in Python 3.9What is new in Python 3.9
What is new in Python 3.9
 
Programming in Python on Steroid
Programming in Python on SteroidProgramming in Python on Steroid
Programming in Python on Steroid
 
The matplotlib Library
The matplotlib LibraryThe matplotlib Library
The matplotlib Library
 
Pandas meetup 20200908
Pandas meetup 20200908Pandas meetup 20200908
Pandas meetup 20200908
 
The num py_library_20200818
The num py_library_20200818The num py_library_20200818
The num py_library_20200818
 
Jupyter notebook 20200728
Jupyter notebook 20200728Jupyter notebook 20200728
Jupyter notebook 20200728
 
Node.js Crash Course (Jump Start)
Node.js Crash Course (Jump Start) Node.js Crash Course (Jump Start)
Node.js Crash Course (Jump Start)
 

Recently uploaded

TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERRORTROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERRORTier1 app
 
SOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar Research Team: Latest Activities of IntelBrokerSOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar Research Team: Latest Activities of IntelBrokerSOCRadar
 
Using IESVE for Room Loads Analysis - Australia & New Zealand
Using IESVE for Room Loads Analysis - Australia & New ZealandUsing IESVE for Room Loads Analysis - Australia & New Zealand
Using IESVE for Room Loads Analysis - Australia & New ZealandIES VE
 
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...informapgpstrackings
 
Breaking the Code : A Guide to WhatsApp Business API.pdf
Breaking the Code : A Guide to WhatsApp Business API.pdfBreaking the Code : A Guide to WhatsApp Business API.pdf
Breaking the Code : A Guide to WhatsApp Business API.pdfMeon Technology
 
AI/ML Infra Meetup | Reducing Prefill for LLM Serving in RAG
AI/ML Infra Meetup | Reducing Prefill for LLM Serving in RAGAI/ML Infra Meetup | Reducing Prefill for LLM Serving in RAG
AI/ML Infra Meetup | Reducing Prefill for LLM Serving in RAGAlluxio, Inc.
 
Mastering Windows 7 A Comprehensive Guide for Power Users .pdf
Mastering Windows 7 A Comprehensive Guide for Power Users .pdfMastering Windows 7 A Comprehensive Guide for Power Users .pdf
Mastering Windows 7 A Comprehensive Guide for Power Users .pdfmbmh111980
 
Crafting the Perfect Measurement Sheet with PLM Integration
Crafting the Perfect Measurement Sheet with PLM IntegrationCrafting the Perfect Measurement Sheet with PLM Integration
Crafting the Perfect Measurement Sheet with PLM IntegrationWave PLM
 
AI/ML Infra Meetup | ML explainability in Michelangelo
AI/ML Infra Meetup | ML explainability in MichelangeloAI/ML Infra Meetup | ML explainability in Michelangelo
AI/ML Infra Meetup | ML explainability in MichelangeloAlluxio, Inc.
 
Into the Box 2024 - Keynote Day 2 Slides.pdf
Into the Box 2024 - Keynote Day 2 Slides.pdfInto the Box 2024 - Keynote Day 2 Slides.pdf
Into the Box 2024 - Keynote Day 2 Slides.pdfOrtus Solutions, Corp
 
Abortion ^Clinic ^%[+971588192166''] Abortion Pill Al Ain (?@?) Abortion Pill...
Abortion ^Clinic ^%[+971588192166''] Abortion Pill Al Ain (?@?) Abortion Pill...Abortion ^Clinic ^%[+971588192166''] Abortion Pill Al Ain (?@?) Abortion Pill...
Abortion ^Clinic ^%[+971588192166''] Abortion Pill Al Ain (?@?) Abortion Pill...Abortion Clinic
 
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2
 
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoamOpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoamtakuyayamamoto1800
 
A Python-based approach to data loading in TM1 - Using Airflow as an ETL for TM1
A Python-based approach to data loading in TM1 - Using Airflow as an ETL for TM1A Python-based approach to data loading in TM1 - Using Airflow as an ETL for TM1
A Python-based approach to data loading in TM1 - Using Airflow as an ETL for TM1KnowledgeSeed
 
Accelerate Enterprise Software Engineering with Platformless
Accelerate Enterprise Software Engineering with PlatformlessAccelerate Enterprise Software Engineering with Platformless
Accelerate Enterprise Software Engineering with PlatformlessWSO2
 
Designing for Privacy in Amazon Web Services
Designing for Privacy in Amazon Web ServicesDesigning for Privacy in Amazon Web Services
Designing for Privacy in Amazon Web ServicesKrzysztofKkol1
 
De mooiste recreatieve routes ontdekken met RouteYou en FME
De mooiste recreatieve routes ontdekken met RouteYou en FMEDe mooiste recreatieve routes ontdekken met RouteYou en FME
De mooiste recreatieve routes ontdekken met RouteYou en FMEJelle | Nordend
 
top nidhi software solution freedownload
top nidhi software solution freedownloadtop nidhi software solution freedownload
top nidhi software solution freedownloadvrstrong314
 

Recently uploaded (20)

TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERRORTROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
 
SOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar Research Team: Latest Activities of IntelBrokerSOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar Research Team: Latest Activities of IntelBroker
 
Using IESVE for Room Loads Analysis - Australia & New Zealand
Using IESVE for Room Loads Analysis - Australia & New ZealandUsing IESVE for Room Loads Analysis - Australia & New Zealand
Using IESVE for Room Loads Analysis - Australia & New Zealand
 
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
 
Breaking the Code : A Guide to WhatsApp Business API.pdf
Breaking the Code : A Guide to WhatsApp Business API.pdfBreaking the Code : A Guide to WhatsApp Business API.pdf
Breaking the Code : A Guide to WhatsApp Business API.pdf
 
AI/ML Infra Meetup | Reducing Prefill for LLM Serving in RAG
AI/ML Infra Meetup | Reducing Prefill for LLM Serving in RAGAI/ML Infra Meetup | Reducing Prefill for LLM Serving in RAG
AI/ML Infra Meetup | Reducing Prefill for LLM Serving in RAG
 
Mastering Windows 7 A Comprehensive Guide for Power Users .pdf
Mastering Windows 7 A Comprehensive Guide for Power Users .pdfMastering Windows 7 A Comprehensive Guide for Power Users .pdf
Mastering Windows 7 A Comprehensive Guide for Power Users .pdf
 
Crafting the Perfect Measurement Sheet with PLM Integration
Crafting the Perfect Measurement Sheet with PLM IntegrationCrafting the Perfect Measurement Sheet with PLM Integration
Crafting the Perfect Measurement Sheet with PLM Integration
 
AI/ML Infra Meetup | ML explainability in Michelangelo
AI/ML Infra Meetup | ML explainability in MichelangeloAI/ML Infra Meetup | ML explainability in Michelangelo
AI/ML Infra Meetup | ML explainability in Michelangelo
 
Top Mobile App Development Companies 2024
Top Mobile App Development Companies 2024Top Mobile App Development Companies 2024
Top Mobile App Development Companies 2024
 
Into the Box 2024 - Keynote Day 2 Slides.pdf
Into the Box 2024 - Keynote Day 2 Slides.pdfInto the Box 2024 - Keynote Day 2 Slides.pdf
Into the Box 2024 - Keynote Day 2 Slides.pdf
 
Abortion ^Clinic ^%[+971588192166''] Abortion Pill Al Ain (?@?) Abortion Pill...
Abortion ^Clinic ^%[+971588192166''] Abortion Pill Al Ain (?@?) Abortion Pill...Abortion ^Clinic ^%[+971588192166''] Abortion Pill Al Ain (?@?) Abortion Pill...
Abortion ^Clinic ^%[+971588192166''] Abortion Pill Al Ain (?@?) Abortion Pill...
 
Corporate Management | Session 3 of 3 | Tendenci AMS
Corporate Management | Session 3 of 3 | Tendenci AMSCorporate Management | Session 3 of 3 | Tendenci AMS
Corporate Management | Session 3 of 3 | Tendenci AMS
 
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
 
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoamOpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
 
A Python-based approach to data loading in TM1 - Using Airflow as an ETL for TM1
A Python-based approach to data loading in TM1 - Using Airflow as an ETL for TM1A Python-based approach to data loading in TM1 - Using Airflow as an ETL for TM1
A Python-based approach to data loading in TM1 - Using Airflow as an ETL for TM1
 
Accelerate Enterprise Software Engineering with Platformless
Accelerate Enterprise Software Engineering with PlatformlessAccelerate Enterprise Software Engineering with Platformless
Accelerate Enterprise Software Engineering with Platformless
 
Designing for Privacy in Amazon Web Services
Designing for Privacy in Amazon Web ServicesDesigning for Privacy in Amazon Web Services
Designing for Privacy in Amazon Web Services
 
De mooiste recreatieve routes ontdekken met RouteYou en FME
De mooiste recreatieve routes ontdekken met RouteYou en FMEDe mooiste recreatieve routes ontdekken met RouteYou en FME
De mooiste recreatieve routes ontdekken met RouteYou en FME
 
top nidhi software solution freedownload
top nidhi software solution freedownloadtop nidhi software solution freedownload
top nidhi software solution freedownload
 

PHP 5.4 New Features

  • 1. PHP 5.4 New Features LifeMichael.com Haim Michael October 14th, 2012 All logos, trade marks and brand names used in this presentation belong to the respective owners.
  • 2. Table of Content LifeMichael.com ● Support for Traits ● Arrays Short Syntax ● Function Array Dereferencing ● PHP Short Tags ● Instantiation Member Access ● Binary Number Format ● Session Upload Process ● Development Web Server
  • 3. Support for Traits LifeMichael.com ● PHP 5.4 we can define Traits. Defining a trait is very similar to defining a class. Instead of using the keyword class we use the keyword trait. ● The purpose of traits is to group functionality in a fine grained and consistent way. ● It is not possible to instantiate a trait. The trait servers as an additional capability when using inheritance in our code.
  • 4. Support for Traits LifeMichael.com <?php trait Academic { function think() { echo "i m thinking!"; } }
  • 5. Support for Traits LifeMichael.com class Person { private $id; private $name; function __construct($idValue,$nameValue) { $this->id = $idValue; $this->name = $nameValue; } function __toString() { return "id=".$this->id." name=".$this->name; } }
  • 6. Support for Traits LifeMichael.com class Student extends Person { use Academic; private $avg; function __construct($idVal,$nameVal,$avgVal) { parent::__construct($idVal,$nameVal); $this->avg = $avgVal; } function __toString() { $str = parent::__toString(); return "avg=".$this->avg.$str; } }
  • 7. Support for Traits LifeMichael.com class Lecturer extends Person { use Academic; private $degree; function __construct($idVal,$nameVal,$degreeVal) { parent::__construct($idVal,$nameVal); $this->degree = $degreeVal; } function __toString() { $str = parent::__toString(); return "degree=".$this->degree.$str; } }
  • 8. Support for Traits LifeMichael.com $student = new Student(123123,"mosh",98); $lecturer = new Lecturer(42343,"dan","mba"); $student->think(); echo "<hr/>"; $lecturer->think(); ?>
  • 9. Support for Traits LifeMichael.com ● Methods of the current class override methods we inserted using the trait. ● Methods inserted by a trait override methods inherited from a base class. ● We can insert multiple traits into one class by listing them in the use statement separated by commas. ● If two traits (or more) insert two (or more) methods with the same name then a fatal error is produced.
  • 10. Support for Traits LifeMichael.com ● We can use the insteadof operator in order to choose the exact method we want to use. ● We can use the as operator in order to include a conflicting method under another name.
  • 11. Support for Traits LifeMichael.com <?php trait Player { function play() { echo "<h1>whoo-a</h1>"; } function printdetails() { echo "<h1>player...</h1>"; } } trait Gamer { function play() { echo "<h1>shoooo</h1>"; } function printdetails() { echo "<h1>gamer...</h1>"; } }
  • 12. Support for Traits LifeMichael.com class Person { use Gamer, Player { Gamer::printdetails insteadof Player; Player::play insteadof Gamer; Gamer::play as xplay; } } $ob = new Person(); $ob->xplay(); $ob->play(); $ob->printdetails(); ?>
  • 13. Support for Traits LifeMichael.com ● We can define a trait composed of others. Doing so we can put together separated traits into one. trait Gamer { function play() { echo "play..."; } } trait Gambler { function gamble() { echo "gamble..."; } }
  • 14. Support for Traits LifeMichael.com trait GamblingGamer { use Gambler, Gamer; } class User { use GamblingGamer; } $ob = new User(); $ob->gamble(); $ob->play(); ?>
  • 15. Support for Traits LifeMichael.com ● We can define a trait that includes the definition for abstract methods. Doing so, we can use that trait to impose requirements upon the classes that use it. ● It is possible to define our trait with properties. When instantiating a class that uses our trait we will be able to refer those properties in the new created object. If the class that uses our trait includes the definition for a property with the same name we will get an error.
  • 16. Arrays Short Syntax LifeMichael.com ● As of PHP 5.4 we can create new arrays in the following new short syntax: <?php $vec_b = ['a'=>'australia','b'=>'belgium','c'=>'canada']; foreach($vec_b as $k=>$v) { echo " ".$k."=>".$v; } ?>
  • 17. Function Array Dereferncing LifeMichael.com ● As of PHP 5.4 we can develop a function that returns an array and use a call to that function as if it was an array. <?php function countries() { $vec = [“italy”,”france”,”israel”]; return $vec; } echo countries()[0]; ?>
  • 18. PHP Short Tags LifeMichael.com ● PHP 5.4 supports the <?…?> and <?= expression ?> short tags by default. We don't need to introduce any change in php.ini in order to use them. <? $numA = 24; $numB = 4; ?> <h1><?=($numA+$numB)?></h1>
  • 19. Instantiation Member Access LifeMichael.com ● PHP 5.4 allows us to access class members on the object instantiation. It is useful in those cases when we need to access a single member of an object and don't need the object. <? class Utils { function calc($numA,$numB) { return $numA+$numB; } } $temp = (new Utils())->calc(3,4); echo $temp; ?>
  • 20. Binary Number Format LifeMichael.com ● PHP 5.4 allows us to write binary numbers. We just need to precede our number with 0b. <? $a = 0b101; $b = 0b110; $c = $a + $b; echo $c; // 11 ?>
  • 21. Session Upload Process LifeMichael.com ● PHP 5.4 allows us to get detailed information about the files that are currently been uploaded. The form might be looking like this. <?php $key = ini_get("session.upload_progress.prefix"). $_POST[ini_get("session.upload_progress.name")]; var_dump($_SESSION[$key]); ?> <form action="upload.php" method="POST" enctype="multipart/form-data"> <input type="hidden" name="<?php echo ini_get("session.upload_progress.name"); ?>" value="123" /> <input type="file" name="file1" /> <input type="file" name="file2" /> <input type="file" name="file3" /> <input type="submit" /> </form>
  • 22. Development Web Server LifeMichael.com ● PHP 5.4 includes a built-in web server. This server might assist during the development phase.
  • 23. Questions & Answers LifeMichael.com ● Two courses you might find interesting include PHP Cross Platform Mobile Applications more info .NET Cloud Based Web Applications more info Android 4.1 Applications Development more info ● If you enjoyed my lecture please leave me a comment at http://speakermix.com/life-michael. Thanks for your time! Haim.