learning php 7

Post on 12-Apr-2017

938 Views

Category:

Technology

1 Downloads

Preview:

Click to see full reader

TRANSCRIPT

ED LOMONACOGR DEV DAY 2016

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

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

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

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

PHP 7 Highlights

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

handling

PHPNG Figures

PHPNG Figures

HOW WILL PHP 7 BREAK MY LEGACY CODE?

Breaking Changes

Breaking Changes

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

code

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

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

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.

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

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

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.

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

New Features

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

Null Coalescing Operator

Ternary on steroids. Useful for when using isset()

Null Coalescing can be chained Will return the first defined value

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

Unicode Escape Syntax

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

Bind Closure on Call

Shorthand to Closure->bindTo()

Group Use Declarations

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

Can be applied to the following: Methods Constants Class

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

Anonymous Classes

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

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

Questions?

Code Example

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

top related