PHP 7 is the latest big release for PHP, in this session you’ll learn what’s new and what to expect in terms of upgrading your current code work to the new version of PHP.
Azure Monitor & Application Insight to monitor Infrastructure & Application
Learning php 7
1. E D L O M O N A C O
G R D E V D A Y 2 0 1 6
Learning PHP 7
2. About Me
Work At Terryberry
Started PHP programming in 2001
PHP 4.1 was the latest release
I’ve Since Learned C# & Java
PHP is still my favorite programming language
I have a programming blog
Eman's Programming Hub
http://emansprogramminghub.blogspot.com
3. Quick History Recap
PHP 4 was released in 2000
PHP 5 was released in 2004
PHP 6 Got caught up in disputes
PHP group fought about Unicode support
PHP 6 dissolved shortly after
PHP 7 was released December 2015
4. Why PHP 7?
PHP 6 has too much baggage
Most of what PHP 6 was going to offer got added in
future PHP 5 releases
PHP 6 is considered an experimental release
PHP 7 just made sense
5. PHP 7 Highlights
64-Bit Windows Support
64-bit support in the past was considered experimental
Lots of depreciated functions are gone
Most of them were considered deprecated back in PHP 5
Old APIs & extensions are gone as well
6. PHP 7 Highlights
New Zend engine (PHPNG)
PHP operates twice as fast with better memory handling
9. H O W W I L L P H P 7 B R E A K M Y L E G A C Y C O D E ?
Breaking Changes
10. Breaking Changes
E_STRICT has been reclassified
The constant is still available to avoid breaking legacy code
11. 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
recommended
Various 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
12. 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 pointer
Hexadecimal strings are no longer considered
numeric
13. 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.
14. 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
15. 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 depreciated
Division by zero will now return either NAN or float
Used to return boolean
16. 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.
17. H O W C A N I M A K E M Y C O D E M O R E A W E S O M E
W I T H P H P 7 ?
New Features
18. 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
19. Null Coalescing Operator
Ternary on steroids.
Useful for when using isset()
Null Coalescing can be chained
Will return the first defined value
20. Combined Comparison
Also known as the Spaceship Operator
Used to compare two expressions
It’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
21. Unicode Escape Syntax
Allows you to enter Unicode character code inside
PHP string
Hexidecimal format
23. Group Use Declarations
Allows for a cleaner way to grab multiple objects
from similar namespace
Can be applied to the following:
Methods
Constants
Class
24. Throwable
PHP Errors are now exceptions
Allows you to better control how to use the error provided
Was known as EngineException during development
EngineException replaced with Throwable in PHP 7 alpha 2
Throwable is the base interface that all errors
reference
Exceptions are also connected to Throwable
25. Anonymous Classes
Like a regular PHP Class but anonymous
C# & Java already do this
Best suited for one-time processes
You can inherit interfaces & classes