What's New In PHP7
-
Upload
petra-barus -
Category
Technology
-
view
3.689 -
download
0
Transcript of What's New In PHP7
![Page 1: What's New In PHP7](https://reader036.fdocuments.net/reader036/viewer/2022081520/58a673631a28abb47e8b67bf/html5/thumbnails/1.jpg)
What’s New In PHP7Petra Novandi Barus
Chief Technology OfficerUrbanIndo.com
Contact Me!email: [email protected] twitter: @petrabarustelegram: petrabarusgithub: petrabarus
Deep insight Laravel, Magento, dan PHP720th February 2016
D.Lab, Jakarta
![Page 2: What's New In PHP7](https://reader036.fdocuments.net/reader036/viewer/2022081520/58a673631a28abb47e8b67bf/html5/thumbnails/2.jpg)
Who Am I?
![Page 3: What's New In PHP7](https://reader036.fdocuments.net/reader036/viewer/2022081520/58a673631a28abb47e8b67bf/html5/thumbnails/3.jpg)
- Chief Technology Officer, UrbanIndo.com- Master of Informatics Engineering ITB- Have been using PHP since 2003- Writes Yii2 libraries - Interests: Distributed systems, High
performance computing, Programming- Hobby: Sleeping, reading books
![Page 4: What's New In PHP7](https://reader036.fdocuments.net/reader036/viewer/2022081520/58a673631a28abb47e8b67bf/html5/thumbnails/4.jpg)
I really love reading about technologies and share the articles on my Twitter!
Follow my reading list at @petrabarus Let’s learn stuffs together!
![Page 5: What's New In PHP7](https://reader036.fdocuments.net/reader036/viewer/2022081520/58a673631a28abb47e8b67bf/html5/thumbnails/5.jpg)
What Am I Going To Talk About?
![Page 6: What's New In PHP7](https://reader036.fdocuments.net/reader036/viewer/2022081520/58a673631a28abb47e8b67bf/html5/thumbnails/6.jpg)
What’s New In PHP7?
What’s New In PHP7 (Internally)?What makes PHP7 much faster and
what can I learn from that?
How do the new PHP7 helps me to code?
![Page 7: What's New In PHP7](https://reader036.fdocuments.net/reader036/viewer/2022081520/58a673631a28abb47e8b67bf/html5/thumbnails/7.jpg)
So, what’s new in PHP7?
![Page 8: What's New In PHP7](https://reader036.fdocuments.net/reader036/viewer/2022081520/58a673631a28abb47e8b67bf/html5/thumbnails/8.jpg)
1. Scalar Type Hints
![Page 9: What's New In PHP7](https://reader036.fdocuments.net/reader036/viewer/2022081520/58a673631a28abb47e8b67bf/html5/thumbnails/9.jpg)
1. Scalar Type Hints Reasons
Type safety Detect bugs before run time Static analysis More robust code
Weak versus Strong Weak: coercive, will cast on different type Strong: strict, will throw TypeError.
![Page 10: What's New In PHP7](https://reader036.fdocuments.net/reader036/viewer/2022081520/58a673631a28abb47e8b67bf/html5/thumbnails/10.jpg)
2. Return Type Declaration
Similar reason with Type Hinting
![Page 11: What's New In PHP7](https://reader036.fdocuments.net/reader036/viewer/2022081520/58a673631a28abb47e8b67bf/html5/thumbnails/11.jpg)
3. Combined Comparison Operator (spaceship)
PHP 5PHP 7
![Page 12: What's New In PHP7](https://reader036.fdocuments.net/reader036/viewer/2022081520/58a673631a28abb47e8b67bf/html5/thumbnails/12.jpg)
3. Combined Comparison Operator (spaceship)
PHP 5
PHP 7
![Page 13: What's New In PHP7](https://reader036.fdocuments.net/reader036/viewer/2022081520/58a673631a28abb47e8b67bf/html5/thumbnails/13.jpg)
4. Null Coalesce Operator (??)
![Page 14: What's New In PHP7](https://reader036.fdocuments.net/reader036/viewer/2022081520/58a673631a28abb47e8b67bf/html5/thumbnails/14.jpg)
5. Anonymous Class Creates an object of a class without defining the class. Pass the value of outer class / object using the
constructor.
![Page 15: What's New In PHP7](https://reader036.fdocuments.net/reader036/viewer/2022081520/58a673631a28abb47e8b67bf/html5/thumbnails/15.jpg)
5. Anonymous Class
![Page 16: What's New In PHP7](https://reader036.fdocuments.net/reader036/viewer/2022081520/58a673631a28abb47e8b67bf/html5/thumbnails/16.jpg)
5. Anonymous Class
PHP 5
PHP 7
![Page 17: What's New In PHP7](https://reader036.fdocuments.net/reader036/viewer/2022081520/58a673631a28abb47e8b67bf/html5/thumbnails/17.jpg)
5. Anonymous Class
![Page 18: What's New In PHP7](https://reader036.fdocuments.net/reader036/viewer/2022081520/58a673631a28abb47e8b67bf/html5/thumbnails/18.jpg)
5. Anonymous Class Usage
Creating a very simple class, one time use. Quickly override one or few methods Implements a specific usage of an interface without defining new class (logger, event observer).
Mocking a class on the fly for testing purposes.
![Page 19: What's New In PHP7](https://reader036.fdocuments.net/reader036/viewer/2022081520/58a673631a28abb47e8b67bf/html5/thumbnails/19.jpg)
6. PerformanceAccording to HHVM…..
![Page 20: What's New In PHP7](https://reader036.fdocuments.net/reader036/viewer/2022081520/58a673631a28abb47e8b67bf/html5/thumbnails/20.jpg)
6. PerformanceAccording to Zend…..
![Page 21: What's New In PHP7](https://reader036.fdocuments.net/reader036/viewer/2022081520/58a673631a28abb47e8b67bf/html5/thumbnails/21.jpg)
What makes PHP 7 faster than PHP 5?
Reference:http://www.slideshare.net/nikita_ppv/php-7-what-changed-internally-php-barcelona-2015http://www.slideshare.net/nikita_ppv/php-7-what-changed-internally http://www.slideshare.net/jpauli/php-7-performances-from-php-5
![Page 22: What's New In PHP7](https://reader036.fdocuments.net/reader036/viewer/2022081520/58a673631a28abb47e8b67bf/html5/thumbnails/22.jpg)
CPU Cache & Memory Architecture
Size LatencyL1 Cache 32kB 1nsL2 Cache 256kB 4nsL3 Cache 4000kB 12nsMemory 2000+MB 100ns
A bit intro to low level optimization by utilizing CPU cache and memory architecture
![Page 23: What's New In PHP7](https://reader036.fdocuments.net/reader036/viewer/2022081520/58a673631a28abb47e8b67bf/html5/thumbnails/23.jpg)
CPU Cache & Memory Architecture
Much faster because using CPU cache
Consider these C codes
![Page 24: What's New In PHP7](https://reader036.fdocuments.net/reader036/viewer/2022081520/58a673631a28abb47e8b67bf/html5/thumbnails/24.jpg)
CPU Cache & Memory Architecture
Reference:https://software.intel.com/en-us/articles/how-to-use-loop-blocking-to-optimize-memory-use-on-32-bit-intel-architecture
![Page 25: What's New In PHP7](https://reader036.fdocuments.net/reader036/viewer/2022081520/58a673631a28abb47e8b67bf/html5/thumbnails/25.jpg)
Memory Optimization Reduce the number of allocations
PHP5 spends 20% of CPU time in allocator
Memory
![Page 26: What's New In PHP7](https://reader036.fdocuments.net/reader036/viewer/2022081520/58a673631a28abb47e8b67bf/html5/thumbnails/26.jpg)
Memory Optimization Reduce Memory Usage
Memory access has high latency Less data => more fits to cache
![Page 27: What's New In PHP7](https://reader036.fdocuments.net/reader036/viewer/2022081520/58a673631a28abb47e8b67bf/html5/thumbnails/27.jpg)
Memory Optimization Reduce Indirection
Remove the number of pointers use
![Page 28: What's New In PHP7](https://reader036.fdocuments.net/reader036/viewer/2022081520/58a673631a28abb47e8b67bf/html5/thumbnails/28.jpg)
Zval Zval is how PHP stores the variables (boolean, integer,
string, array). Zval is short of Zend Value. In PHP 7, Zval is optimized.
Less allocation Less indirection Less memory usage
![Page 29: What's New In PHP7](https://reader036.fdocuments.net/reader036/viewer/2022081520/58a673631a28abb47e8b67bf/html5/thumbnails/29.jpg)
Zval
PHP 5 PHP 7
![Page 30: What's New In PHP7](https://reader036.fdocuments.net/reader036/viewer/2022081520/58a673631a28abb47e8b67bf/html5/thumbnails/30.jpg)
ZvalPHP5- Zvals always
require heap allocation
- Zvals always reference counted and have cycle collection
PHP7- Zvals are no longer
heap-allocated and no ref count.
- Ref count in the complex value
- No double refcount. - Complex type can be
shared
![Page 31: What's New In PHP7](https://reader036.fdocuments.net/reader036/viewer/2022081520/58a673631a28abb47e8b67bf/html5/thumbnails/31.jpg)
ZVal PHP5
![Page 32: What's New In PHP7](https://reader036.fdocuments.net/reader036/viewer/2022081520/58a673631a28abb47e8b67bf/html5/thumbnails/32.jpg)
ZValPHP7
![Page 33: What's New In PHP7](https://reader036.fdocuments.net/reader036/viewer/2022081520/58a673631a28abb47e8b67bf/html5/thumbnails/33.jpg)
More Data Structure Optimization HashTable (array)
4 pointer indirections & 100~ byte memory to 2 pointer indirections & 32 byte memory.
String management Refcounted
![Page 34: What's New In PHP7](https://reader036.fdocuments.net/reader036/viewer/2022081520/58a673631a28abb47e8b67bf/html5/thumbnails/34.jpg)
AST PHP 7 introduces Abstract Syntax Tree Instead of single pass parse-compile, PHP7 will do
syntax analysis and then parse
![Page 35: What's New In PHP7](https://reader036.fdocuments.net/reader036/viewer/2022081520/58a673631a28abb47e8b67bf/html5/thumbnails/35.jpg)
ASTPHP5
PHP7
![Page 36: What's New In PHP7](https://reader036.fdocuments.net/reader036/viewer/2022081520/58a673631a28abb47e8b67bf/html5/thumbnails/36.jpg)
AST
PHP5
![Page 37: What's New In PHP7](https://reader036.fdocuments.net/reader036/viewer/2022081520/58a673631a28abb47e8b67bf/html5/thumbnails/37.jpg)
AST
PHP7
![Page 38: What's New In PHP7](https://reader036.fdocuments.net/reader036/viewer/2022081520/58a673631a28abb47e8b67bf/html5/thumbnails/38.jpg)
2. AST Well designed and well maintain Better syntax checking and consistency Slower to run but produce much better runtime
opcode Use opcode cache for this
Breaks backward compatibility
![Page 39: What's New In PHP7](https://reader036.fdocuments.net/reader036/viewer/2022081520/58a673631a28abb47e8b67bf/html5/thumbnails/39.jpg)
Reference http://
www.slideshare.net/colinodell/php-7-crash-course-phpworld-2015
http://www.slideshare.net/nikita_ppv/php-7-what-changed-internally-php-barcelona-2015
http://www.slideshare.net/nikita_ppv/php-7-what-changed-internally
https://nikic.github.io/2015/05/05/Internal-value-representation-in-PHP-7-part-1.html
![Page 40: What's New In PHP7](https://reader036.fdocuments.net/reader036/viewer/2022081520/58a673631a28abb47e8b67bf/html5/thumbnails/40.jpg)
Conclusion PHP7 is way better than PHP5
Much faster Use less memory Produce robust code (Check your backward compatibility due to AST change)
You should use PHP7!
![Page 41: What's New In PHP7](https://reader036.fdocuments.net/reader036/viewer/2022081520/58a673631a28abb47e8b67bf/html5/thumbnails/41.jpg)
Questions?