learning php 7

27
ED LOMONACO GR DEV DAY 2016 Learning PHP 7

Upload: ed-lomonaco

Post on 12-Apr-2017

937 views

Category:

Technology


1 download

TRANSCRIPT

Page 1: Learning php 7

ED LOMONACOGR DEV DAY 2016

Learning PHP 7

Page 2: Learning php 7

About Me

Work At TerryberryStarted PHP programming in 2001

PHP 4.1 was the latest releaseI’ve Since Learned C# & JavaPHP is still my favorite programming

languageI have a programming blog

Eman's Programming Hub http://emansprogramminghub.blogspot.com

Page 3: Learning php 7

Quick History Recap

PHP 4 was released in 2000PHP 5 was released in 2004PHP 6 Got caught up in disputes

PHP group fought about Unicode support PHP 6 dissolved shortly after

PHP 7 was released December 2015

Page 4: Learning php 7

Why PHP 7?

PHP 6 has too much baggageMost of what PHP 6 was going to offer got

added in future PHP 5 releasesPHP 6 is considered an experimental releasePHP 7 just made sense

Page 5: Learning php 7

PHP 7 Highlights

64-Bit Windows Support 64-bit support in the past was considered

experimentalLots of depreciated functions are gone

Most of them were considered deprecated back in PHP 5

Old APIs & extensions are gone as well

Page 6: Learning php 7

PHP 7 Highlights

New Zend engine (PHPNG) PHP operates twice as fast with better memory

handling

Page 7: Learning php 7

PHPNG Figures

Page 8: Learning php 7

PHPNG Figures

Page 9: Learning php 7

HOW WILL PHP 7 BREAK MY LEGACY CODE?

Breaking Changes

Page 10: Learning php 7

Breaking Changes

E_STRICT has been reclassified The constant is still available to avoid breaking legacy

code

Page 11: Learning php 7

Breaking Changes

ASP-Style & Script tags are no longer supported

All ereg functions are gone ereg was deprecated a while ago and using preg_* is

recommendedVarious database-specific functions are gone

mysql mssql

list function cannot be empty It can’t be used to unpack string variables, use

str_split() The ordering of assignment has been reversed

Page 12: Learning php 7

Breaking Changes

global only accepts simple variables Variable variables can only be used if wrapped around

curly braces; that is discouraged however.foreach will not change the array pointerHexadecimal strings are no longer

considered numeric

Page 13: Learning php 7

Breaking Changes

Various mcrypt functions are removed mcrypt_generic_end() ;

mcrypt_generic_deinit() is preferred mcrypt_ecb(), mcrypt_cbc(), mcrypt_cfb() and

mcrypt_ofb() mcrypt_decrypt() with the appropriate MCRYPT_MODE_*

constant.GD Type1 functions are removed

Using TrueType fonts and their associated functions is recommended instead.

Page 14: Learning php 7

Breaking Changes

New objects can no longer be assigned by reference Was depreciated in PHP 5

Non-static methods cannot be called as static Was depreciated in PHP 5.6

$HTTP_RAW_POST_DATA is removed php://input is the recommended method

JSON has been replaced with JSOND Numbers cannot end with decimal point

Page 15: Learning php 7

Breaking Changes

Functions can’t have similar-named variables Will throw an E_COMPILE_ERROR

Switch statement can’t have multiple default blocks Will throw an E_COMPILE_ERROR

PHP 4 style constructors are depreciatedDivision by zero will now return either NAN

or float Used to return boolean

Page 16: Learning php 7

Uniform Variable Syntax

Uniform Variable Syntax is an effort to making PHP more consistent.

It’ll be read strictly left to right from now on.

Page 17: Learning php 7

HOW CAN I MAKE MY CODE MORE AWESOME WITH PHP 7?

New Features

Page 18: Learning php 7

Scalar Type Hints & Return Types

You can now tell a function or method what it should accept and return int bool string float

Type hinting is non-strict by default declare(strict_types=1); will make type hinting strict

Page 19: Learning php 7

Null Coalescing Operator

Ternary on steroids. Useful for when using isset()

Null Coalescing can be chained Will return the first defined value

Page 20: Learning php 7

Combined Comparison

Also known as the Spaceship OperatorUsed to compare two expressionsIt’ll return -1, 0, or 1

-1 => The leftmost value is smaller 0 => Both values are equal 1 => The leftmost value is greater

Can be used with any type

Page 21: Learning php 7

Unicode Escape Syntax

Allows you to enter Unicode character code inside PHP string Hexidecimal format

Page 22: Learning php 7

Bind Closure on Call

Shorthand to Closure->bindTo()

Page 23: Learning php 7

Group Use Declarations

Allows for a cleaner way to grab multiple objects from similar namespace

Can be applied to the following: Methods Constants Class

Page 24: Learning php 7

Throwable

PHP Errors are now exceptions Allows you to better control how to use the error

providedWas known as EngineException during

development EngineException replaced with Throwable in PHP 7

alpha 2Throwable is the base interface that all errors

reference Exceptions are also connected to Throwable

Page 25: Learning php 7

Anonymous Classes

Like a regular PHP Class but anonymous C# & Java already do this

Best suited for one-time processesYou can inherit interfaces & classes

Page 26: Learning php 7

Questions?

Page 27: Learning php 7

Code Example

https://github.com/eman1986/PHP7-Examples